Java Code Examples for com.sun.xml.internal.messaging.saaj.util.ByteOutputStream#size()

The following examples show how to use com.sun.xml.internal.messaging.saaj.util.ByteOutputStream#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IOUtil.java    From gameserver with Apache License 2.0 5 votes vote down vote up
/**
 * Compress the string with ZIP method.
 * @param content
 * @return
 */
public static byte[] compressString(String entryName, String content) {
	try {
		ByteOutputStream bos = new ByteOutputStream(10000);
		ZipOutputStream zos = new ZipOutputStream(bos);
		ZipEntry entry = new ZipEntry(entryName);
		zos.putNextEntry(entry);
		zos.write(content.getBytes("utf8"));
		zos.flush();
		zos.close();
		byte[] fileBytes = new byte[bos.size()];
		System.arraycopy(bos.getBytes(), 0, fileBytes, 0, fileBytes.length);
		return fileBytes;
	} catch (IOException e) {
		logger.warn("Failed to zip string.", e);
	}
	return null;
}
 
Example 2
Source File: IOUtil.java    From gameserver with Apache License 2.0 5 votes vote down vote up
public static byte[] compressStringZlib(String content) {
	try {
		ByteOutputStream bos = new ByteOutputStream(10000);
		DeflaterOutputStream zos = new DeflaterOutputStream(bos);
		zos.write(content.getBytes("utf8"));
		zos.flush();
		zos.close();
		byte[] fileBytes = new byte[bos.size()];
		System.arraycopy(bos.getBytes(), 0, fileBytes, 0, fileBytes.length);
		return fileBytes;
	} catch (IOException e) {
		logger.warn("Failed to zip string.", e);
	}
	return null;
}