I am currently analyzing firmware images which contain many different sections, one of which is a GZIP section. I am able to know the location of the start of the GZIP section using magic number and the GZIPInputStream in Java. However, I need to know the compressed size of the gzip section. GZIPInputStream w…
Tag: java
Singleton using AtomicReference
Is it correct implementation of lazy-initializing singleton using AtomicReference? If no – what are the possible issues? Answer No, this is bad: Using an AtomicReference is a nice idea, but it won’t work because Java doesn’t have lazy evaluation. The classic post 1.5 singleton methods are: E…
Regular expression to match unescaped special characters only
I’m trying to come up with a regular expression that can match only characters not preceded by a special escape sequence in a string. For instance, in the string Is ? stranded//? , I want to be able to replace the ? which hasn’t been escaped with another string, so I can have this result : **Is Da…
How to set an expiration date in java
I am trying to write some code to correctly set an expiration date given a certain date. For instance this is what i have. However, say if i the sign up date is on 5/7/2011 the expiration date output i get is on 11/6/2011 which is not exactly half of a year from the given date. Is there an easier
HttpClient 4.1.1 returns 401 when authenticating with NTLM, browsers work fine
I’m trying to use the Apache/Jakarta HttpClient 4.1.1 to connect to an arbitrary web page using the given credentials. To test this, I have a minimal install of IIS 7.5 on my dev machine running where only one authentication mode is active at a time. Basic authentication works fine, but Digest and NTLM …
How to make javax Transformer output HTML (no self-closing tags)?
I’m using a javax.xml.transform.Transformer to convert an XML file into an HTML file. It can happen that a div will have no content, which causes the Transformer to output <div/>, which breaks rendering. I’ve searched and found that “You can change the xslt output to html instead of xm…
Base64 decoding using JDK6 only
This question with regard to JDK 5 says, there is no implementation provided with JDK 5, but JDK 6 is supposed to have a sun.misc.Base64Decoder. As far as I can tell though, this class is not provided with the JDK and I was not able to find any other similar classes in itSo, what is the situation like with JD…
IntelliJ inspection gives “Cannot resolve symbol” but still compiles code
Platform: IntelliJ Community Edition 10.0.3 SDK: jdk1.6.0_21 OS: Windows 7 So I have a strange situation with IntelliJ that has me completely stumped. I setup a Maven project and add log4j as a dependency in the pom.xml file. The IDEA inspections run fine and my unit tests all compile and run. I then added hu…
How do I do calendar arithmetic with java.util.Date?
Currently I have a Date object representing a time. How would I add 5 minutes to this object? Answer You could use Calendar, which will make it easy to add any length of time: For your case you could just add the time in milliseconds like this:
calling numbered function name in loop using java reflection
i have a problem as : MyFirstClass.java MySecondClass.java TestClass.java I want to use java reflection and call the pObj.getP**Param() methods in for loop by providing the parameters to g How it can be made possible. I don’t want to use array of p*Params. Thanks in advance. Answer Are you sure this is …