Created
March 8, 2023 20:47
-
-
Save muhdkhokhar/1e49ccdedc489ecfefd6a158d09adb8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.jms.Message; | |
import org.springframework.util.ErrorHandler; | |
public class MyJmsErrorHandler implements ErrorHandler { | |
@Override | |
public void handleError(Throwable t) { | |
// Handle the error here | |
} | |
@Override | |
public void handleError(String message, Throwable t) { | |
// Handle the error here | |
} | |
@Override | |
public void handleWarning(String message, Throwable t) { | |
// Handle the warning here | |
} | |
} | |
@JmsListener(destination = "myQueue", containerFactory = "jmsListenerContainerFactory", messageConverter = "gzipMessageConverter", errorHandler = "myJmsErrorHandler") | |
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.IOException; | |
import java.util.Base64; | |
import java.util.zip.GZIPInputStream; | |
import java.util.zip.GZIPOutputStream; | |
public class CompressionUtils { | |
public static String compress(String input) throws IOException { | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
GZIPOutputStream gzipOut = new GZIPOutputStream(baos); | |
gzipOut.write(input.getBytes()); | |
gzipOut.close(); | |
return Base64.getEncoder().encodeToString(baos.toByteArray()); | |
} | |
public static String decompress(String input) throws IOException { | |
byte[] compressed = Base64.getDecoder().decode(input); | |
ByteArrayInputStream bais = new ByteArrayInputStream(compressed); | |
GZIPInputStream gzipIn = new GZIPInputStream(bais); | |
byte[] buffer = new byte[1024]; | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
int len; | |
while ((len = gzipIn.read(buffer)) != -1) { | |
baos.write(buffer, 0, len); | |
} | |
gzipIn.close(); | |
baos.close(); | |
return new String(baos.toByteArray()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment