me.moocar.logbackgelf.Zipper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of logback-gelf Show documentation
Show all versions of logback-gelf Show documentation
GELF Appender for logback. Use this appender to log messages to a graylog2 server via GELF messages.
package me.moocar.logbackgelf;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
public class Zipper {
/**
* zips up a string into a GZIP format.
*
* @param str The string to zip
* @return The zipped string
*/
public byte[] zip(String str) {
GZIPOutputStream zipStream = null;
try {
ByteArrayOutputStream targetStream = new ByteArrayOutputStream();
zipStream = new GZIPOutputStream(targetStream);
zipStream.write(str.getBytes());
zipStream.close();
byte[] zipped = targetStream.toByteArray();
targetStream.close();
return zipped;
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
try {
if (zipStream != null) {
zipStream.close();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy