本文整理汇总了Java中java.util.zip.Deflater.DEFAULT_COMPRESSION属性的典型用法代码示例。如果您正苦于以下问题:Java Deflater.DEFAULT_COMPRESSION属性的具体用法?Java Deflater.DEFAULT_COMPRESSION怎么用?Java Deflater.DEFAULT_COMPRESSION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.util.zip.Deflater
的用法示例。
在下文中一共展示了Deflater.DEFAULT_COMPRESSION属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compress
private static byte[] compress(byte[] data) throws IOException {
Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
deflater.setInput(data);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
deflater.finish();
byte[] buffer = new byte[1024];
while (!deflater.finished()) {
int count = deflater.deflate(buffer);
outputStream.write(buffer, 0, count);
}
outputStream.close();
byte[] output = outputStream.toByteArray();
Log.d("Compressor", "Original: " + data.length);
Log.d("Compressor", "Compressed: " + output.length);
return output;
}
示例2: openFile
protected void openFile() {
try {
FileAccess fa = database.getFileAccess();
java.io.OutputStream fos = fa.openOutputStreamElement(outFile);
outDescriptor = fa.getFileSync(fos);
fileStreamOut = new DeflaterOutputStream(fos,
new Deflater(Deflater.DEFAULT_COMPRESSION), bufferSize);
} catch (IOException e) {
throw Error.error(ErrorCode.FILE_IO_ERROR,
ErrorCode.M_Message_Pair, new Object[] {
e.toString(), outFile
});
}
}
示例3: testNowrap
@Test
public void testNowrap() throws IOException {
// Recompress with nowrap set to false.
Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, false /* nowrap */);
ByteArrayOutputStream compressedContentBuffer = new ByteArrayOutputStream();
DeflaterOutputStream deflateOut = new DeflaterOutputStream(compressedContentBuffer, deflater);
deflateOut.write(CONTENT);
deflateOut.finish();
deflateOut.close();
deflater.end();
compressedContent = compressedContentBuffer.toByteArray();
compressedContentIn = new ByteArrayInputStream(compressedContent);
// Now expect wrapped content in the uncompressor, and uncompressing should "just work".
uncompressor.setNowrap(false);
uncompressor.uncompress(compressedContentIn, uncompressedContentOut);
assertTrue(Arrays.equals(CONTENT, uncompressedContentOut.toByteArray()));
}
示例4: openFile
protected void openFile() throws HsqlException {
try {
FileAccess fa = database.getFileAccess();
java.io.OutputStream fos = fa.openOutputStreamElement(outFile);
outDescriptor = fa.getFileSync(fos);
fileStreamOut = new DeflaterOutputStream(fos,
new Deflater(Deflater.DEFAULT_COMPRESSION), bufferSize);
} catch (IOException e) {
throw Trace.error(Trace.FILE_IO_ERROR, Trace.Message_Pair,
new Object[] {
e.toString(), outFile
});
}
}
示例5: TIFFDeflater
public TIFFDeflater(String compressionType,
int compressionTagValue,
ImageWriteParam param,
int predictorValue) {
super(compressionType, compressionTagValue, true);
this.predictor = predictorValue;
// Set the deflate level.
int deflateLevel;
if(param != null &&
param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
float quality = param.getCompressionQuality();
deflateLevel = (int)(1 + 8*quality);
} else {
deflateLevel = Deflater.DEFAULT_COMPRESSION;
}
this.deflater = new Deflater(deflateLevel);
}
示例6: getContentPayload
@Override
public byte[] getContentPayload() {
byte[] payload = new byte[(width+1)*height];
for(int i = 0; i<height ; i++) {
int offset = i * (width+1);
//NO filter on this line
payload[offset++] = 0;
for(int j = 0 ; j<width ; j++) {
payload[offset+j] = (byte)(127);
}
}
Deflater deflater = new Deflater( Deflater.DEFAULT_COMPRESSION );
ByteArrayOutputStream outBytes = new ByteArrayOutputStream((width+1)*height);
DeflaterOutputStream compBytes = new DeflaterOutputStream( outBytes, deflater );
try {
compBytes.write(payload);
compBytes.close();
} catch(Exception e) {
e.printStackTrace();
}
byte[] compPayload = outBytes.toByteArray();
return compPayload;
}
示例7: getZipCompressionLevel
private int getZipCompressionLevel(FuzzyCompressionLevel compressionLevel) {
switch (compressionLevel) {
case BEST:
return Deflater.BEST_COMPRESSION;
case FASTEST:
return Deflater.BEST_SPEED;
case NONE:
return Deflater.NO_COMPRESSION;
case DEFAULT:
default:
return Deflater.DEFAULT_COMPRESSION;
}
}
示例8: setUp
@Before
public void setUp() throws IOException {
ByteArrayOutputStream compressedContentBuffer = new ByteArrayOutputStream();
Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
DeflaterOutputStream deflateOut = new DeflaterOutputStream(compressedContentBuffer, deflater);
deflateOut.write(CONTENT);
deflateOut.finish();
deflateOut.close();
deflater.end();
compressedContent = compressedContentBuffer.toByteArray();
uncompressor = new DeflateUncompressor();
compressedContentIn = new ByteArrayInputStream(compressedContent);
uncompressedContentOut = new ByteArrayOutputStream();
}
示例9: openFile
protected void openFile() throws HsqlException {
try {
FileOutputStream fos = new FileOutputStream(outFile, true);
outDescriptor = fos.getFD();
fileStreamOut = new DeflaterOutputStream(fos,
new Deflater(Deflater.DEFAULT_COMPRESSION), bufferSize);
} catch (IOException e) {
throw Trace.error(Trace.FILE_IO_ERROR, Trace.Message_Pair,
new Object[] {
e.getMessage(), outFile
});
}
}
示例10: getDeflater
private Deflater getDeflater() {
synchronized (deflaters) {
int size = deflaters.size();
if (size > 0) {
Deflater def = deflaters.remove(size - 1);
return def;
} else {
return new Deflater(Deflater.DEFAULT_COMPRESSION, true);
}
}
}
示例11: setLevel0
private void setLevel0(int level) {
if ((level < Deflater.NO_COMPRESSION || Deflater.BEST_COMPRESSION < level)
&& level != Deflater.DEFAULT_COMPRESSION)
throw new IllegalArgumentException("Invalid compression level!");
this.level = level;
}
示例12: GzipStreamSinkConduit
public GzipStreamSinkConduit(ConduitFactory<StreamSinkConduit> conduitFactory, HttpServerExchange exchange) {
super(conduitFactory, exchange, Deflater.DEFAULT_COMPRESSION);
writeHeader();
}
示例13: createDeflater
private static Deflater createDeflater()
{
// The second argument (nowrap) is true to get only DEFLATE
// blocks without the ZLIB header and checksum fields.
return new Deflater(Deflater.DEFAULT_COMPRESSION, true);
}
示例14: ZipOutputStream
/**
* Creates a new ZIP output stream.
*
* @param out the actual output stream
*/
public ZipOutputStream(OutputStream out) {
super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
usesDefaultDeflater = true;
}
示例15: getLevel
/**
* {@inheritDoc}
* <p>
* The implementation in the class {@link DefaultZipOutputStreamParameters}
* returns {@code Deflater#DEFAULT_COMPRESSION}.
*/
@Override
public int getLevel() {
return Deflater.DEFAULT_COMPRESSION;
}