Java Generics difference between wildcard and generic parameter type
Could someone explain to me why the third method doesnt compile?
public class Test{
public <K> void test(List<K> list){ //Compiles
K n = list.get(0);
}
public void test(List<? extends Number> list){ //Compiles
Number n = list.get(0);
}
public <K> void test(List<K extends Number> list){ //Doesn't compile !!
Number n = list.get(0);
}
}
Bushard
Sunday, 1 September 2013
Replacing/removing a line in a text file in java
Replacing/removing a line in a text file in java
public void removeLine() {
try {
File dir = new File("chars");
if(dir.exists()) {
String read;
File files[] = dir.listFiles();
for (int j = 0; j < files.length; j++) {
File loaded = files[j];
if (loaded.getName().endsWith(".txt")) {
Scanner s = new Scanner (loaded);
while (s.hasNextLine()) {
read = s.nextLine();
if (read.contains("char-15")) {
read.replace(read, "");
System.out.println(loaded.getName() +" -
Data: "+read);
break;
}
}
}
}
}
} catch (Exception e) {
}
}
What this should do is replace each line that contains "char-15", with an
empty String.
When I run this though, it doesn't delete the line in all the files. I
can't do this manually as there are well over 5000 files.
How can I make it delete this specific line in all of the files?
public void removeLine() {
try {
File dir = new File("chars");
if(dir.exists()) {
String read;
File files[] = dir.listFiles();
for (int j = 0; j < files.length; j++) {
File loaded = files[j];
if (loaded.getName().endsWith(".txt")) {
Scanner s = new Scanner (loaded);
while (s.hasNextLine()) {
read = s.nextLine();
if (read.contains("char-15")) {
read.replace(read, "");
System.out.println(loaded.getName() +" -
Data: "+read);
break;
}
}
}
}
}
} catch (Exception e) {
}
}
What this should do is replace each line that contains "char-15", with an
empty String.
When I run this though, it doesn't delete the line in all the files. I
can't do this manually as there are well over 5000 files.
How can I make it delete this specific line in all of the files?
save image to server from canvas
save image to server from canvas
hi i wanna take image from webcam and save it in server;i use following
code but it does not work.my code take pic and show it in mycanvas but
when i want to get image from mycanvas and send it to server ajax function
does not work.
var webcam = (function () {
var video = document.createElement('video'),
photo = document.getElementById("myCanvas");
function play() {
if (navigator.getUserMedia) {
navigator.getUserMedia({ video: true,
audio: true, toString: function () { return
"video,audio"; } }, onSuccess, onError);
} else {
changeStatus('getUserMedia is not supported
in this browser.', true);
}
}
function onSuccess(stream) {
var source;
if (window.webkitURL) {
source =
window.webkitURL.createObjectURL(stream);
} else {
source = stream;
// Opera and Firefox
}
video.autoplay = true;
video.src = source;
changeStatus('Connected.', false);
}
function onError() {
changeStatus('Please accept the getUserMedia
permissions! Refresh to try again.', true);
}
function changeStatus(msg, error) {
var status = document.getElementById('status');
status.innerHTML = msg;
status.style.color = (error) ? 'red' : 'green';
}
var status = document.getElementById()
function setupPhotoBooth() {
var takeButton =
document.getElementById('btnTakePicture');
takeButton.addEventListener('click', takePhoto,
true);
var saveButton =
document.getElementById('btnSave');
saveButton.disabled = true;
saveButton.addEventListener('click', savePhoto,
true);
}
function takePhoto() {
// set our canvas to the same size as our video
photo.width = video.width;
photo.height = video.height;
var context = photo.getContext('2d');
context.drawImage(video, 0, 0, photo.width,
photo.height);
// allow us to save
var saveButton =
document.getElementById('btnSave');
saveButton.disabled = false;
var data = photo.toDataURL("image/png");
data = data.replace("image/png", "");
document.getElementById("<%= eventdata.ClientID
%>").value = data;
}
return {
init: function () {
changeStatus('Please accept the permissions
dialog.', true);
video.width = 320;
video.height = 240;
document.body.appendChild(video);
document.body.appendChild(photo);
navigator.getUserMedia ||
(navigator.getUserMedia =
navigator.mozGetUserMedia ||
navigator.webkitGetUserMedia ||
navigator.msGetUserMedia);
play();
setupPhotoBooth();
} ()
}
})();
function UploadPic() {
// generate the image data
var Pic =
document.getElementById("myCanvas").toDataURL("image/png");
// var Pic =
document.getElementById("eventdata").toDataURL("image/png");
Pic = Pic.replace(/^data:image\/(png|jpg);base64,/, "")
// Sending the image data to Server
$.ajax({
type: 'POST',
url: 'Save_Picture.aspx/UploadPic',
data: '{ "imageData" : "' + Pic + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert("Done, Picture Uploaded.");
}
});
}
hi i wanna take image from webcam and save it in server;i use following
code but it does not work.my code take pic and show it in mycanvas but
when i want to get image from mycanvas and send it to server ajax function
does not work.
var webcam = (function () {
var video = document.createElement('video'),
photo = document.getElementById("myCanvas");
function play() {
if (navigator.getUserMedia) {
navigator.getUserMedia({ video: true,
audio: true, toString: function () { return
"video,audio"; } }, onSuccess, onError);
} else {
changeStatus('getUserMedia is not supported
in this browser.', true);
}
}
function onSuccess(stream) {
var source;
if (window.webkitURL) {
source =
window.webkitURL.createObjectURL(stream);
} else {
source = stream;
// Opera and Firefox
}
video.autoplay = true;
video.src = source;
changeStatus('Connected.', false);
}
function onError() {
changeStatus('Please accept the getUserMedia
permissions! Refresh to try again.', true);
}
function changeStatus(msg, error) {
var status = document.getElementById('status');
status.innerHTML = msg;
status.style.color = (error) ? 'red' : 'green';
}
var status = document.getElementById()
function setupPhotoBooth() {
var takeButton =
document.getElementById('btnTakePicture');
takeButton.addEventListener('click', takePhoto,
true);
var saveButton =
document.getElementById('btnSave');
saveButton.disabled = true;
saveButton.addEventListener('click', savePhoto,
true);
}
function takePhoto() {
// set our canvas to the same size as our video
photo.width = video.width;
photo.height = video.height;
var context = photo.getContext('2d');
context.drawImage(video, 0, 0, photo.width,
photo.height);
// allow us to save
var saveButton =
document.getElementById('btnSave');
saveButton.disabled = false;
var data = photo.toDataURL("image/png");
data = data.replace("image/png", "");
document.getElementById("<%= eventdata.ClientID
%>").value = data;
}
return {
init: function () {
changeStatus('Please accept the permissions
dialog.', true);
video.width = 320;
video.height = 240;
document.body.appendChild(video);
document.body.appendChild(photo);
navigator.getUserMedia ||
(navigator.getUserMedia =
navigator.mozGetUserMedia ||
navigator.webkitGetUserMedia ||
navigator.msGetUserMedia);
play();
setupPhotoBooth();
} ()
}
})();
function UploadPic() {
// generate the image data
var Pic =
document.getElementById("myCanvas").toDataURL("image/png");
// var Pic =
document.getElementById("eventdata").toDataURL("image/png");
Pic = Pic.replace(/^data:image\/(png|jpg);base64,/, "")
// Sending the image data to Server
$.ajax({
type: 'POST',
url: 'Save_Picture.aspx/UploadPic',
data: '{ "imageData" : "' + Pic + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert("Done, Picture Uploaded.");
}
});
}
Saturday, 31 August 2013
C++ error C2228
C++ error C2228
I'll admit I'm not sure of what I'm doing here, so I am doing a lot of
copying sample code from my textbook and replacing with info for my own
program... but can tell me what is causing this error?
Car.cpp
// Implementation file for the Car class
#include "Car.h"
// This constructor accepts arguments for the car's year
// and make. The speed member variable is assigned 0.
Car::Car(int carYearModel, string carMake)
{
yearModel = carYearModel;
make = carMake;
speed = 0;
}
Car.h
// Specification file for the Car class
#ifndef CAR_H
#define CAR_H
#include <string>
using namespace std;
class Car
{
private:
int yearModel; // Car year model
string make; // Car make
int speed; // Car speed
public:
Car(int, string); // Constructor
};
I'll admit I'm not sure of what I'm doing here, so I am doing a lot of
copying sample code from my textbook and replacing with info for my own
program... but can tell me what is causing this error?
Car.cpp
// Implementation file for the Car class
#include "Car.h"
// This constructor accepts arguments for the car's year
// and make. The speed member variable is assigned 0.
Car::Car(int carYearModel, string carMake)
{
yearModel = carYearModel;
make = carMake;
speed = 0;
}
Car.h
// Specification file for the Car class
#ifndef CAR_H
#define CAR_H
#include <string>
using namespace std;
class Car
{
private:
int yearModel; // Car year model
string make; // Car make
int speed; // Car speed
public:
Car(int, string); // Constructor
};
Change a text file in random access
Change a text file in random access
I have a Text file and want to Change it in some places for example in
4030 t0 4060, in this way :if there is a character 'C' or 'c' followed by
'G' or 'g' ,must be changed in 'B' character ,the input file is a text
file and i want to get a changed text output file , there is no random
access in text file and must open file in binary form and make changes but
the output file will be binary and i dont have any idea to get a text
output .the codes are in below:
int main()
{
string str,cstr;
ReadTextFile("in",4030,4060);
return 0;
}
string ReadTextFile(string path, int from, int to)
{
fstream fp(path.c_str(),ios::in|ios::out| ios::binary);
char * target;
string res,str;
target = new char[to - from + 1];
if (!target)
{
cout << "Cannot allocate memory." << endl;
return "";
}
fp.seekg(from);
fp.read(target, to - from);
target[to - from] = 0;
res = target;
str=changestring(res);
fp.seekg(from);
fp.write((char *)&str,to-from);
return res;
}
string changestring(string str)
{
int l=str.length();
l=l-1;
for(int i=0;i<= l;i++)
{
if(str[i]=='C' || str[i]=='c')
{
int j=i+1;
if(str[j]=='G' || str[j]=='g')
str[i]='B';
}
}
return str;
}
I have a Text file and want to Change it in some places for example in
4030 t0 4060, in this way :if there is a character 'C' or 'c' followed by
'G' or 'g' ,must be changed in 'B' character ,the input file is a text
file and i want to get a changed text output file , there is no random
access in text file and must open file in binary form and make changes but
the output file will be binary and i dont have any idea to get a text
output .the codes are in below:
int main()
{
string str,cstr;
ReadTextFile("in",4030,4060);
return 0;
}
string ReadTextFile(string path, int from, int to)
{
fstream fp(path.c_str(),ios::in|ios::out| ios::binary);
char * target;
string res,str;
target = new char[to - from + 1];
if (!target)
{
cout << "Cannot allocate memory." << endl;
return "";
}
fp.seekg(from);
fp.read(target, to - from);
target[to - from] = 0;
res = target;
str=changestring(res);
fp.seekg(from);
fp.write((char *)&str,to-from);
return res;
}
string changestring(string str)
{
int l=str.length();
l=l-1;
for(int i=0;i<= l;i++)
{
if(str[i]=='C' || str[i]=='c')
{
int j=i+1;
if(str[j]=='G' || str[j]=='g')
str[i]='B';
}
}
return str;
}
How do I float one image on top of another?
How do I float one image on top of another?
I've done some searching on this topic, but I can't seem to find an answer
that's exactly what I'm looking for.
I'm trying to set up a banner ad (728 x 90) on my site so it is "laid
over" a div with a background image. Therefore, if someone has an
adblocker, they'll see an image that says "please disable your adblock"
where the ad should be.
My current code is this:
<div style="float: left; background-image:
url(../forum/banners/replacement.png); height: 90px; width: 728px; border:
1px solid black;">
</div>
<!-- BEGIN SMOWTION TAG - 728x90 - DO NOT MODIFY -->
<script type="text/javascript">
<!-- ad code goes here -->
</script>
<!-- END SMOWTION TAG - 728x90 - DO NOT MODIFY -->
However, this makes the ad show up under the div, instead of appearing
'overlaid' on it. How can I make it so that the ad and the div don't clip?
I've done some searching on this topic, but I can't seem to find an answer
that's exactly what I'm looking for.
I'm trying to set up a banner ad (728 x 90) on my site so it is "laid
over" a div with a background image. Therefore, if someone has an
adblocker, they'll see an image that says "please disable your adblock"
where the ad should be.
My current code is this:
<div style="float: left; background-image:
url(../forum/banners/replacement.png); height: 90px; width: 728px; border:
1px solid black;">
</div>
<!-- BEGIN SMOWTION TAG - 728x90 - DO NOT MODIFY -->
<script type="text/javascript">
<!-- ad code goes here -->
</script>
<!-- END SMOWTION TAG - 728x90 - DO NOT MODIFY -->
However, this makes the ad show up under the div, instead of appearing
'overlaid' on it. How can I make it so that the ad and the div don't clip?
Hide variable value
Hide variable value
I'm writing a small Android app and I need to hide some variable values. I
have a API key I got from the content provider who is providing me content
to show in my app that I need to retrieve data from them. Because it is
being used in an encryption algorithm, it is of vital importance the code
isn't leaked.
I need to save the API key in my code and be sure it isn't retrievable by
the bad people in the world. What I do now, is save them in my code as a
variable:
private static final String API_KEY="mysupersecreatapikey";
After the app is compiled to an APK file, this is, in my opinion not
retrievable anymore. Am I doing it in the right way now, or is there a
better solution?
Thx in advance, Daryl
I'm writing a small Android app and I need to hide some variable values. I
have a API key I got from the content provider who is providing me content
to show in my app that I need to retrieve data from them. Because it is
being used in an encryption algorithm, it is of vital importance the code
isn't leaked.
I need to save the API key in my code and be sure it isn't retrievable by
the bad people in the world. What I do now, is save them in my code as a
variable:
private static final String API_KEY="mysupersecreatapikey";
After the app is compiled to an APK file, this is, in my opinion not
retrievable anymore. Am I doing it in the right way now, or is there a
better solution?
Thx in advance, Daryl
Subscribe to:
Posts (Atom)