Exception in thread "main" java.util.zip.DataFormatException: incorrect header check
By : Amit
Date : March 29 2020, 07:55 AM
wish helps you Couple of problems with your code here: 1) Your assumption is the Byte Array output1 returned with deflator can be a valid String without a valid encoding - evident from your code here: code :
String str=new String(output1);
byte output2[]=str.getBytes("UTF-8");
byte[] result = new byte[10000];
int resultLength = decompresser.inflate(result);
byte[] output1 = new byte[input.length];
import org.apache.axis.encoding.Base64;
public static void main(String[] args) {
try {
// Encode a String into bytes
String inputString = "Pehla nasha Pehla khumaar Naya pyaar hai naya intezaar Kar loon main kya apna haal Aye dil-e-bekaraar Mere dil-e-bekaraar Tu hi bata Pehla nasha Pehla khumaar Udta hi firoon in hawaon mein kahin Ya main jhool jaoon in ghataon mein kahin Udta hi firoon in hawaon mein kahin Ya main jhool jaoon in ghataon mein kahin Ek kar doon aasmaan zameen Kaho yaaron kya karoon kya nahin Pehla nasha Pehla khumaar Naya pyaar hai naya intezaar Kar loon main kya apna haal Aye dil-e-bekaraar Mere dil-e-bekaraar Tu hi bata Pehla nasha Pehla khumaar Usne baat ki kuchh aise dhang se Sapne de gaya vo hazaaron range ke Usne baat ki kuchh aise dhang se Sapne de gaya vo hazaaron range ke Reh jaoon jaise main haar ke Aur choome vo mujhe pyaar se Pehla nasha Pehla khumaar Naya pyaar hai naya intezaar Kar loon main kya apna haal Aye dil-e-bekaraar Mere dil-e-bekaraar";
byte[] input = inputString.getBytes("UTF-8");
// Compress the bytes
byte[] output1 = new byte[input.length];
Deflater compresser = new Deflater();
compresser.setInput(input);
compresser.finish();
int compressedDataLength = compresser.deflate(output1);
compresser.end();
String str = Base64.encode(output1);
System.out.println("Deflated String:" + str);
byte[] output2 = Base64.decode(str);
// Decompress the bytes
Inflater decompresser = new Inflater();
decompresser.setInput(output2);
byte[] result = str.getBytes();
int resultLength = decompresser.inflate(result);
decompresser.end();
// Decode the bytes into a String
String outputString = new String(result, 0, resultLength, "UTF-8");
System.out.println("Deflated String:" + outputString);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DataFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Deflated String:eJzNUbtuwzAM/BX+QD4iQ6eiRdDH0PESM6YsWwpku4X99Tna7lC03QK0g42TeOQdTwe1FpLQG+Sw4GhjBxR5xAS5TA4NgRQeQxp09pt7fm3OSTqEJJElXBJIRCv7SaUK7U53R40oTn/Q8u3uZRQLcsTwKfyTideKZdLOobgatQwfcF11XRj/b1hdNJZzKw02Ym0c/ZV522l3kaBI5Qygp98kMzrVxHgsi0eX13DIyxtMS+/vG/+P2Puk5GCQGCSOJzNB6DnLkGoheKYujyq1+3vPtDCv6xYyVKLeZMaT2vYEzdK7rG3ukMX9WOTEV+rUm7uxMd2CI/PPAr4Cer8r5QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Deflated String:Pehla nasha Pehla khumaar Naya pyaar hai naya intezaar Kar loon main kya apna haal Aye dil-e-bekaraar Mere dil-e-bekaraar Tu hi bata Pehla nasha Pehla khumaar Udta hi firoon in hawaon mein kahin Ya main jhool jaoon in ghataon mein kahin Udta hi firoon in hawaon mein kahin Ya main jhool jaoon in ghataon mein kahin Ek kar doon aasmaan zameen Kaho yaaron kya karoon kya nahin Pehla nasha Pehla khumaar Naya pyaar hai naya intezaar Kar loon main kya apna haal Aye dil-e-bekaraar Mere dil-e-bekaraar Tu hi bata Pehla nasha Pehla khumaar Usne baat ki kuchh aise dhang se Sapne de gaya vo hazaaron range ke Usne baat ki kuchh aise dhang se Sapne de gaya vo hazaaron range ke Reh jaoon jaise main haar ke Aur choome vo mujhe pyaar se Pehla nasha Pehla khumaar Naya pyaar hai naya intezaar Kar loon main kya apna haal Aye dil-e-bekaraar Mere dil-e-bekaraar
|
How can there be a dot(.) in interfaces like Thread.UncaughtExceptionHandler or Map.Entry?
By : crawford johan
Date : March 29 2020, 07:55 AM
This might help you If we see the definitions like Thread.UncaughtExceptionHandler or Map.Entry in oracle docs, they are defined as public static interface. Wanted to know how is that achieved or written internally by Java? Because when we try to create some customize interface of similar pattern, the compiler throws exception at the dot(.)! , It's because of an nested type. Like, code :
public class Thread {
public static interface UncaughtExceptionHandler {
//interface members
void uncaughtException(Thread t, Throwable e);
}
}
public class ThreadGroup implements Thread.UncaughtExceptionHandler {
//implementation to the uncaughtException method.
}
|
How to set UncaughtExceptionHandler for a thread group
By : Abhishek Singh
Date : March 29 2020, 07:55 AM
I wish this helpful for you TL;DR Subclass the ThreadGroup and override the uncaughtException() method. A ThreadGroup is an UncaughtExceptionHandler, implementing the uncaughtException(Thread t, Throwable e) method: code :
public class ExceptionHandlingThreadGroup extends ThreadGroup {
private UncaughtExceptionHandler uncaughtExceptionHandler;
public ExceptionHandlingThreadGroup(String name) {
super(name);
}
public ExceptionHandlingThreadGroup(ThreadGroup parent, String name) {
super(parent, name);
}
public UncaughtExceptionHandler getUncaughtExceptionHandler() {
return this.uncaughtExceptionHandler;
}
public void setUncaughtExceptionHandler(UncaughtExceptionHandler uncaughtExceptionHandler) {
this.uncaughtExceptionHandler = uncaughtExceptionHandler;
}
@Override
public void uncaughtException(Thread t, Throwable e) {
if (this.uncaughtExceptionHandler != null)
this.uncaughtExceptionHandler.uncaughtException(t, e);
else
super.uncaughtException(t, e);
}
}
|
GWT - Unable to catch StatusCodeException with UncaughtExceptionHandler
By : MrLw
Date : March 29 2020, 07:55 AM
Any of those help When Tomcat session times out, I want to redirect my user to the homepage of my GWT app, so that they can login again. To force this, I'm trying to use the StatusCodeException thrown by GWT when the user tries to perform any operation after their session times out - , code :
onFailure(Throwable caught) {
logger.error(caught);
}
onFailure(Throwable caught) {
GWT.getUncaughtExceptionHandler().onUncaughtException(ex);
}
public abstract class NetworkAsyncCallback<T> implements AsyncCallback<T> {
@Override
public void onFailure(Throwable t) {
if (e instanceof StatusCodeException) {
logger.log(Level.ERROR, "Exception caught!");
logger.log(Level.ERROR, ((StatusCodeException) e).getStatusCode());
}
}
}
myServer.getSomeData(param, new NetworkAsyncCallback<Result>() {
@Override
public void onSuccess(Result result) {
//...
}
// Skip onFailure, or if you need custom logic, implement it,
// and call super only if the exception isn't part of that logic
});
|
Is it possible to run the java thread in UncaughtExceptionHandler?
By : kazza
Date : March 29 2020, 07:55 AM
it should still fix some issue Yes it is possible to run a Thread in a Thread.UncaughtExceptionHandler.uncaughtException ... provided that the Thread hasn't been started previously. But it is NOT possible to start the Thread that was pass as the t argument. That will (always) be a Thread that has already been started and has terminated.
|