Reputation: 1697
I have a web application, I have several actions. One of the actions writes some image to a folder out of context, lets say to:
/home/user/images/subfolder1/image.jpg
Now, another action copies that image to another folder located inside images, but with a different extension, lets say to:
/home/user/images/subfolder2/subsubfolder2-1/image.png
Now, the first image is get from a form, the second image is get from the path where the first image was saved, both images are written with the same method:
InputStream in = new FileInputStream(origen);
OutputStream out = new FileOutputStream(destination.getAbsolutePath());
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
The webapp creates every folder, including "subfolder2/subsubfolder2-1/" using mkdirs() if they don't exist.
This works just fine in my test enviroment running ubuntu 14.04 with apache tomcat 6.0.43, but, on production, is centos 6(or 6.5), same apache tomcat version, the image is created, but no data is written to it, what I mean, is that a image.png file is created, but its size is 0. All folders have the correct permissions, drwxrwxrwx, but image.png for some reason, lacks them, having only rw.
What can be causing this?
Upvotes: 0
Views: 270
Reputation: 1697
For some uknown reason, I just changed how I write my file to:
InputStream in = new FileInputStream(origen);
OutputStream out = new FileOutputStream(destination.getAbsolutePath());
int byteRead = 0;
byte[] buffer = new byte[8192];
while ((byteRead = in.read(buffer, 0, 8192)) != -1){
out.write(buffer, 0, byteRead);
}
And it worked properly, don't know the reason behind it.
Upvotes: 1