java.util.zip.zipexception : unknown compression method - java

I am working with a third party API http://jortho.sourceforge.net/
While using the API, I always get an exception
java.util.zip.zipexception : unknown compression method
There are no zip files involved, I tried not using the .jar file of the API, instead using the class files directly, but it still gives me the same error.
What possibly could be the reason? How can I start off with my debugging?
There is a class WordIterator which uses java.util.zip.InflaterInputStream but I don't think the problem is with the API.
I am stuck! What can be the possible way out?

I sounds to me as if someone is trying to unzip a corrupted zip-file/stream, or something which isn't a zip-file or stream at all.
Since JOrtho is GPL, your best shot is to get the source code and debug the thing yourself. In Eclipse, you can set an exception breakpoint on ZipException and the debugger will stop immediately before the exception is thrown.

Related

Eclipse - Clipboard exception "ClassNotFoundException"

I am developing an application in Eclipse, with frames. In some of the panels I allow the user to paste data from his clipboard. It is usually quiet. The problem is when what is on the clipboard has been copied from intelliJ (due to IntelliJ causing everything that is copied to become a serialized object) and results in an exception (ClassNotFoundException) and I can't catch it.
Does anyone know how to avoid this, in code?
Exception:
Exception "java.lang.ClassNotFoundException: com/intellij/codeInsight/editorActions/FoldingData"
while constructing DataFlavor for:
application/x-java-jvm-local-objectref;
class=com.intellij.codeInsight.editorActions.FoldingData
The obvious answer would be to catch the exception and ignore it.
If you can't do that, some possibilities are:
Develop a patch to Eclipse that allows a plugin to suppress these exceptions ... somehow1. Then submit an Eclipse bug report, providing your patch as a solution.
Get the user to add the Intellij "idea.jar" file to the Eclipse classpath so that Eclipse can deserialize these objects. You may then need to make further modifications to your plugin to allow it to make sense of the IDEA objects that you user is trying to copy and paste into Eclipse.
Document that your plugin does not support copy / paste from Intellij IDEA.
I couldn't see any way to stop Intellij from putting serialized objects into the clipboard.
UPDATE - I did some more research on this. The string
"while constructing DataFlavor for:"
appears in the source code for java.awt.datatransfer.SystemFlavorMap. That suggests that the problem is actually the same one as has been reported as Java bugs JDK-6606476 and 8246248. (In the latter case, the problem is triggered by certain kinds of JPEG files.)
Examining the source code suggests that it ought to be possible to work around this problem; e.g. by creating and registering a custom DataFlavor and implementing a DataContentHandler / DataContentHandlerFactory to take care of the conversion2. However, I can't give you specifics.
1 - It turns out that the problem is probably NOT in the Eclipse code base after all.
2 - Unless you fancy decoding Java serialization format by hand, I suggest you "deserialize" this stuff as content-free objects ... and get your application to quietly ignore DnD events for this kind of data.

A library I am using is opening an input stream and not closing it. How can I close it?

Every few days, I get a SocketException, too many files open. I tracked the issue to a temporary pdf file that is being used during a certain process. The process passes a name of a temporary file that the library creates. At some point, the library opens an input stream but doesn't close it. Given that my code only has the name of the file, is there any way for me to close the stream?
Details:
Java Web App running in Tomcat6
The best approach is to request a version of this library with this bug fixed.
If this is not possible, get the sources, fix the bug yourself.
If you can't (only a binary jar file), try a tool like jd-gui, decompile the faulty class, fix, recompile that class and replace the .class in the jar.
If it still does not work use ASM and add a close statement at the right place. THIS SOLUTION SHOULD BE AVOIDED. It's complex if you do not master this technology.

Why does getResourceAsStream() not work in JAR files?

I have the following code in a static method:
clips.open(AudioSystem.getAudioInputStream(Sound.class.getResourceAsStream("folder/sound.wav")));
Also, folder is in the same directory as Sound.java. When I run the program in Eclipse, the sound is played. However, when I export the file to a JAR file, the sound no longer plays.
If I change getResourceAsStream() to getResource(), both Eclipse and the JAR file play the sound. Why does this happen? I have read around and many people suggest that getResourceAsStream() simply doesn't work in JAR files. Is this the case, and if so, why not?
I suspect that the issue is that Class.getResourceAsStream(String) returns an InputStream, and Class.getResource(String) returns a URL. Thus, in the first case, we are in effect using
AudioSystem.getAudioInputStream(InputStream inputStream)
and in the second case, using
AudioSystem.getAudioInputStream(URL url).
Why does this matter? I think the main issue is that when the InputStream is the parameter, mark/reset tests are done on your audio file and it is failing. When the URL is used as a parameter, this test does not occur. You might check out the API for AudioSystem.getAudioInputStream to confirm what I am reporting here.
Do you get an error message when the getResourceAsStream fails? Does it mention the mark/reset test error by chance? If you are getting a different error message then this might not be the correct answer and something else is going on.

how to debug kernels called by a java(jcuda) program

Is there any way to debug cuda functions called by java (jcuda) ?
My program launch this exception:
Exception in thread "main" jcuda.CudaException:CUDA_ERROR_ILLEGAL_ADDRESS
at jcuda.driver.JCudaDriver.checkResult(JCudaDriver.java:288)
at jcuda.driver.JCudaDriver.cuCtxSynchronize(JCudaDriver.java:1852)
at CalculateurGPU.updateAndCompute(rGPUcalculator.java:129)
at Test.main(Test.java:90)
I have a very long cuda code, and i can't find any information in that to help me find where the error is.
Another question: when i click on "JCudaDriver.java:288" i don't have access to it, it says "source not found". How can i attach thesesources to my project ?
Thanks in advance
The best way I have been able to debug my JCuda executable code is by putting printf statements everywhere. Obviously delete them after you are done but you have to start somewhere.
Add the following to your .java code that is calling your kernel code.
JCudaDriver.cuCtxSetLimit(CUlimit.CU_LIMIT_PRINTF_FIFO_SIZE, 4096);
Then inside your CUDA kernel, use printf(""); statements in your CUDA kernel code to determine where the problem exists. If I had a guess it would be due to you access a piece of memory that you shouldn't be.
I would also suggest wrapping the printf with a if(gtid == 0){printf("hello\n");} otherwise you are going to have every thread trying to perform the printf.
Source: http://forum.byte-welt.net/byte-welt-projekte-projects/swogl-jcuda-jocl/jcuda/3255-gpu-printf-compute-capility-2-0-a.html
EDIT:
I would like to add that there has been a debugging section added on the JCuda website. It suggests using a tool called "cuda-memcheck" to aid in debugging your CUDA applications.
http://www.jcuda.org/debugging/Debugging.html

Error handling for encoding problems in File.listFiles() in android

I'm fairly new to android and java, my background is c# .net.
I have a network share mounted to /mnt/cifs/Audio by using CifsManager. Other apps on the device can display the files in that directory.
My problem is that my app goes into a loop when calling listFiles() on a File object.
I noticed that it is because there is a file or folder in that share with an invalid Modified UTF-8 name. From LogCat I can see that it is when NewStringUTF is instantiated, obviously this is done internally when I list all the files.
How can I get around this issue? Is there a way to handle that error/exception or is there another way to get all the files & folders without running into this issue?
Any help would be greatly appreciated.
Not really the answer to my question, but it does allow me to do what I intended.
I am now using the JCIFS library to handle all the mounting and so forth. This library then handles the encoding internally and with good results.
It seems to skip those file/directory names that it doesn't recognize and thus provides some form of error handling on the file/directory names.

Categories

Resources