I am trying to convert a signed byte in unsigned. The problem is the data I am receiving is unsigned and Java does not support unsigned byte, so when it reads the data it treats it as signed. I tried …
Tag: java
IllegalAnnotationException: Two classes have the same XML type name
I am developing web service under JBoss 5 and Java 1.6. What could possibly cause this exception? Below is my simplified web service code. And below is the full stack trace. Answer I found the cause of my problem. This problem occurs because JAX-WS generates a class for each method and the class name is const…
Loop through array, each element a JUnit test
I have a JUnit 4 test that loops through an array of test data: Because it’s all in one test method, the whole test stops as soon as one element in the array fails. Is there a way around that, without making a method for each test item? Maybe something with reflection? Answer Use JUnit 4’s paramet…
Comparing arrays in JUnit assertions, concise built-in way?
Is there a concise, built-in way to do equals assertions on two like-typed arrays in JUnit? By default (at least in JUnit 4) it seems to do an instance compare on the array object itself. EG, doesn’t work: Of course, I can do it manually with: ..but is there a better way? Answer Use org.junit.AssertR…
Why doesn’t this generic cast fail?
I’d expect this code to throw a ClassCastException: But it doesn’t. Casting String to T doesn’t fail, until I use the returned object somehow, like: Background: I created a Class which uses JAXB to unmarshal an XML file. It looks like this: Depending on whether the root-Element is an anonymo…
How do I pass kilogram, gram to a kilogram converter and obtain the result in grams
How do I pass kilogram, gram to a kilogram converter and obtain the result in grams (e.g. 5 kg 500 grams = 5500 grams) How to do this using javax.measure.* Refer over here Note: I need the solution only based on the above packages and not some generic solution Answer It’s a rather cumbersome API, but so…
Determine target service/method from CXF Interceptor
I’d like to write an interceptor for the Apache CXF JAX-RS implementation that inspects the target service/method for a particular annotation and does some special processing for that annotation. I can’t seem to find anything in the interceptor documentation that describes how to do this. Does any…
How to scale a BufferedImage
Following the javadocs, I have tried to scale a BufferedImage without success here is my code: I can’t understand why it is not working, any help? Answer AffineTransformOp offers the additional flexibility of choosing the interpolation type. The fragment shown illustrates resampling, not cropping; this …
Negative Number in fillRect()
I am using a negative number to have fillRect() go the opposite way. It works well on my computer, but my friends cannot see it working properly. What do I do? Answer My guess is that you and your freind are using 2 different versions of Java. your supports fillrect with a negative value and your freind’…
How to reliably guess the encoding between MacRoman, CP1252, Latin1, UTF-8, and ASCII
At work it seems like no week ever passes without some encoding-related conniption, calamity, or catastrophe. The problem usually derives from programmers who think they can reliably process a “text” file without specifying the encoding. But you can’t. So it’s been decided to henceforth forbid fil…