shadylookin
December 30th, 2009, 05:05 AM
The jist of my story is this...
I'm running a server in java, This server listens for a command to save pictures. In windows it works just fine however in linux a large portion of the picture data never gets saved to the file.
I've used wireshark to confirm that in fact everything is being send to the server properly. Using a hexeditor I also know that the data that's save to file is actual picture data just missing a large chunk of the first part of the data.
here's the code in question
String line;
int imageCount = 0, imageByte;
try {
Scanner s = new Scanner(socket.getInputStream());
line = s.nextLine();
String[] items = line.split(" ");
if(items.length == 2)
{
String directory = "pictures" + File.separator + items[0] + File.separator + items[1];
new File(directory).mkdirs();
do{
try{
line = s.nextLine();
}catch(NoSuchElementException ex)
{
break;
}
if(line.equals("SAVEPICTURE")){
File imageFile = new File(directory + File.separator + imageCount + ".jpg");
imageCount++;
FileImageOutputStream fios;
byte[] success = {83, 85, 67, 67, 69, 83, 83, 13, 10};
try {
socket.getInputStream().skip(13);
fios = new FileImageOutputStream(imageFile);
System.out.println("Started getting picture");
while((imageByte = socket.getInputStream().read()) != -1){
//if it has reached the END\r\n
System.out.print(imageByte+" ");
if(imageByte == 69 ){//E
if((imageByte = socket.getInputStream().read()) == 78){//N
if((imageByte=socket.getInputStream().read()) == 68){//D
if((imageByte=socket.getInputStream().read()) == 13){//carriage return
if((imageByte=socket.getInputStream().read()) == 10){//new line
break;
} else{
fios.write(69);
fios.write(78);
fios.write(68);
fios.write(13);
fios.write(imageByte);
}
} else{
fios.write(69);
fios.write(78);
fios.write(68);
fios.write(imageByte);
}
} else{
fios.write(69);
fios.write(78);
fios.write(imageByte);
}
}else{
fios.write(69);
fios.write(imageByte);
}
}
else{
fios.write(imageByte);
}
}
fios.flush();
fios.close();
socket.getOutputStream().write(success);
socket.getOutputStream().flush();
System.out.println("finished recieving picture");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}while(!line.equals("QUIT"));
s.close();
}
Anyone have any ideas what's going on or how to solve it?
I'm running a server in java, This server listens for a command to save pictures. In windows it works just fine however in linux a large portion of the picture data never gets saved to the file.
I've used wireshark to confirm that in fact everything is being send to the server properly. Using a hexeditor I also know that the data that's save to file is actual picture data just missing a large chunk of the first part of the data.
here's the code in question
String line;
int imageCount = 0, imageByte;
try {
Scanner s = new Scanner(socket.getInputStream());
line = s.nextLine();
String[] items = line.split(" ");
if(items.length == 2)
{
String directory = "pictures" + File.separator + items[0] + File.separator + items[1];
new File(directory).mkdirs();
do{
try{
line = s.nextLine();
}catch(NoSuchElementException ex)
{
break;
}
if(line.equals("SAVEPICTURE")){
File imageFile = new File(directory + File.separator + imageCount + ".jpg");
imageCount++;
FileImageOutputStream fios;
byte[] success = {83, 85, 67, 67, 69, 83, 83, 13, 10};
try {
socket.getInputStream().skip(13);
fios = new FileImageOutputStream(imageFile);
System.out.println("Started getting picture");
while((imageByte = socket.getInputStream().read()) != -1){
//if it has reached the END\r\n
System.out.print(imageByte+" ");
if(imageByte == 69 ){//E
if((imageByte = socket.getInputStream().read()) == 78){//N
if((imageByte=socket.getInputStream().read()) == 68){//D
if((imageByte=socket.getInputStream().read()) == 13){//carriage return
if((imageByte=socket.getInputStream().read()) == 10){//new line
break;
} else{
fios.write(69);
fios.write(78);
fios.write(68);
fios.write(13);
fios.write(imageByte);
}
} else{
fios.write(69);
fios.write(78);
fios.write(68);
fios.write(imageByte);
}
} else{
fios.write(69);
fios.write(78);
fios.write(imageByte);
}
}else{
fios.write(69);
fios.write(imageByte);
}
}
else{
fios.write(imageByte);
}
}
fios.flush();
fios.close();
socket.getOutputStream().write(success);
socket.getOutputStream().flush();
System.out.println("finished recieving picture");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}while(!line.equals("QUIT"));
s.close();
}
Anyone have any ideas what's going on or how to solve it?