java-sdk-2.8.1.jar from my Java program. In this program using the com.box.sdk.BoxFile download api I download the file from box and process it in my application. The code below works fine with smaller files however when downloading 500 MB file I get java.lang.OutOfMemory error at line file.download(outputStream). Please advise.
public void downloadFile(BoxAPIConnection boxConn,String boxFileID, ByteArrayOutputStream outputStream) throws Exception {
BoxFile file = new BoxFile(boxConn, boxFileID);
file.download(outputStream);
}
Related
We are using Ubuntu server and Java 8 with Spring Boot 1.4.2 release with Docker deployment in Ubuntu. In a folder /home/tempAttachment there are 100 millions of directories and the code:
public synchronized static File getFile(String filePath) throws IOException
{
java.nio.file.Path files12 = null;
File tempFile= new File(filePath);
if(!tempFile.getParentFile().exists())
{
files12 = java.nio.file.Files.createDirectories(java.nio.file.Paths.get(tempFile.getParentFile().getAbsolutePath()));
tempFile= files12.toFile();
}
return tempFile;
}
Gives an error below:
java.nio.file.FileSystemException: /home/TempAttachment/email/plain-2f298db6-6ce0-471a-869d-7cb18fd5f351: No space left on device
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384)
at java.nio.file.Files.createDirectory(Files.java:674)
We are trying to reproduce this error in production in our local laptop, but not able to reproduce. Please help
I have created a JavaEE based web application that I then exported as a WAR file and deployed to a tomcat server that is running on a vm.
The Application allows users to upload an image to a location on the vm disk, and then to run an image processing class that accepts a path to the previously uploaded file.
I am trying to use ImageIO.read() to read in the file as a buffered image.
When running in the IDE, the image processing class works fine and is able to accept the image stored on the disk and output the processed image. However when accessing it as a deployed web application I am met with the error:
HTTP Status 500 - Can't read input file!
type Exception report
message Can't read input file!
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.imageio.IIOException: Can't read input file!
javax.imageio.ImageIO.read(Unknown Source)
upload.servlet.resizeImageAndSaveSobel2.sobelFilter(resizeImageAndSaveSobel2.java:22)
upload.servlet.resizeImageAndSaveSobel2.processImage(resizeImageAndSaveSobel2.java:14)
upload.servlet.RunTongue.doPost(RunTongue.java:24)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
note The full stack trace of the root cause is available in the Apache Tomcat/9.0.0.M13 logs.
This is the code which is a part of the image processing class that reads in the uploaded image:
public void sobelFilter(String input, String output) throws IOException {
File inputFile = new File(input);
BufferedImage img = ImageIO.read(inputFile);
ImageReader ir = new ImageReader();
BufferedImage sobelImg = ir.greyscale(img);
File outputFile = new File(output);
ImageIO.write(sobelImg, "jpg", outputFile);
}
The input file string is as follows: C:/Users/SRCMIPS/Desktop/M2/Image Upload/PatientImage.jpeg
Is this a problem regarding ImageIO.read with a deployed WAR of the project?
Is the application unable to read in images from paths located on the vm?
Any guidance with regards to a solution to this problem would be appreciated.
The VM is external of your system. You need to basically create an image folder in your project and have it read there (/project name/lib name/image name).
Also please see this stackoverflow question that discusses this problem:
imageio.IIOException: Can't read input file
I have integrated Image magick with a Java WebApp and have deployed it on Azure App Service. On azure , I am getting 0kb as output image for a image while the same image gets converted fine on my local machine.
I am using im4java for integration with Image Magick.
Below is the code:
public void compressImage(String imageSource, String destinationPath) throws IOException, InterruptedException,
IM4JavaException {
ConvertCmd cmd = getCommand();
// create the operation, add images and operators/options
IMOperation op = new IMOperation();
op.strip();
op.interlace();
op.addRawArgs(compressionRawArguments);
op.gaussianBlur(compressionGaussianBlur);
op.quality(compressedImageQuality);
op.addImage(imageSource); // source file
op.addImage(destinationPath); // destination file
// execute the operation
cmd.run(op);
}
Both imageSource and destination are temp files created using java. I have checked that imageSource file has correct size but after running this code, the destination file is always 0 Kb.
Please advise what could I be doing wrong?
Answering my own question so that It might be helpful for fellow developers who might face this problem.
Azure App Service normally has Windows Server VMs. You can check the OS of your server in web container logs.
Image Magick for windows does not allow conversion of remote http
image urls while for Unix System, it allows so. My Local machine is
MAC So it was working correctly on my local system.
2 Solutions to this problem that I found:
Either you use a linux VM on Azure
In your application, download the image URL to a temp file and
supply the absolute path of that temp file to image magick for
conversion.
I have tried both and are both working.
I became so much upset with this simple code segment:
FileConnection fc = (FileConnection) Connector.open("file:///root1/photos/2.png");
System.out.println(is.available());
byte[] fileBytes = new byte[is.available()];
int sizef = is.read(fileBytes);
System.out.println("filesize:"+sizef);
When I deploy this midlet in my mobile (with proper file location) It works properly i.e it shows proper filesize, but in the pc emulator it is constantly giving filesize of: 0. Obviously no Exception and I have the proper file in that location.
I am using j2mewtk sdk in netbeans 6.9. I tried uninstalling, installing wtk & netbeans.
Another thing is Everytime I run the emulator it creates C:\Users\Mahsruf\j2mewtk\2.5.2\appdb\temp.DefaultColorPhone6 new location like temp.DefaultColorPhone1,2,3,4 etc.
If I use jme SDK 3.0 in netbeans the file size is still 0, but now with a extra line in output window: [WARN] [rms ] javacall_file_open: _wopen failed for: C:\Users\Mahsruf\javame-sdk\3.0\work\0\appdb\_delete_notify.dat
What am I doing wrong?
This is not coding related issue. If multiple instances of the same emulator skin run simultaneously, the toolkit generates unique file paths for each one. For example, on Windows instances of DefaultColorPhone might have a file path name of workdir\appdb\temp.DefaultColorPhone1, workdir\appdb\temp.DefaultColorPhone2, and so forth.
Solution: The file workdir\appdb\DefaultColorPhone\in.use keeps track of the number of storage roots marked as in use. If the emulator crashes, you need to delete the in.use file
i am getting a problem
i have deployed a war file, when i run localy through tomcat it works fine but when i run on another system by giveing my system ip and then project folder e.g
http:\192.168.0.145\DllTest it loads the applet but when i click on a button to load the functionality it is throwing an exception
Exception in thread "AWT-EventQueue-3" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: http:\192.168.0.145:8080\DllTest\lib\jinvoke.dll
while it is working fine localy but not in another system. Please tell me what is the problem.
Is it a rights issue or something else.
You cannot load a DLL on an external host. It has to be an absolute disk file system -as the exception message already hints. Your best bet is to download it manually, create a temp file and load it instead.
File dllFile = File.createTempFile("jinvoke", ".dll");
InputStream input = new URL(getCodeBase(), "lib/jinvoke.dll").openStream();
OuptutStream output = new FileOutputStream(dllFile);
// Write input to output and close streams the usual Java IO way.
// Then load it using absolute disk file system path.
System.loadLibrary(dllFile.getAbsolutePath());
dllFile.deleteOnExit();