本文整理汇总了Java中java.util.zip.DeflaterInputStream类的典型用法代码示例。如果您正苦于以下问题:Java DeflaterInputStream类的具体用法?Java DeflaterInputStream怎么用?Java DeflaterInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DeflaterInputStream类属于java.util.zip包,在下文中一共展示了DeflaterInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addFile
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
public void addFile(String name, byte[] content, boolean deflate) throws IOException {
byte[] data;
if (deflate) {
ByteArrayInputStream in = new ByteArrayInputStream(content);
DeflaterInputStream def = new DeflaterInputStream(in, new Deflater(9, true));
data = ByteStreams.toByteArray(def);
} else {
data = content;
}
Chain dataChain = new Chain(data, (int) this.getHeader().getDefaultChunkSize(), getContainerContext());
dataChain.setContainerContext(getContainerContext());
Date date = new Date();
Attributes attributes = new Attributes(date, date, 0, name, null, getContainerContext());
Chain attrChain = new Chain(attributes.asByteArray(), (int) this.getHeader().getDefaultChunkSize(), getContainerContext());
attrChain.setContainerContext(getContainerContext());
attributes.setChain(attrChain);
File fl = new File(name, attributes, dataChain, this, getContainerContext());
this.getChains().add(attrChain);
this.getChains().add(dataChain);
this.getFiles().put(fl.getName(), fl);
}
示例2: testReadByteByByte
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
public void testReadByteByByte() throws IOException {
byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
InputStream in = new DeflaterInputStream(new ByteArrayInputStream(data));
ByteArrayOutputStream out = new ByteArrayOutputStream();
assertEquals(1, in.available());
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
assertEquals(0, in.available());
assertEquals(Arrays.toString(data), Arrays.toString(inflate(out.toByteArray())));
in.close();
try {
in.available();
fail();
} catch (IOException expected) {
}
}
示例3: testReadWithBuffer
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
public void testReadWithBuffer() throws IOException {
byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
byte[] buffer = new byte[8];
InputStream in = new DeflaterInputStream(new ByteArrayInputStream(data));
ByteArrayOutputStream out = new ByteArrayOutputStream();
assertEquals(1, in.available());
int count;
while ((count = in.read(buffer, 0, 5)) != -1) {
assertTrue(count <= 5);
out.write(buffer, 0, count);
}
assertEquals(0, in.available());
assertEquals(Arrays.toString(data), Arrays.toString(inflate(out.toByteArray())));
in.close();
try {
in.available();
fail();
} catch (IOException expected) {
}
}
示例4: getInputValues
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
/**
* Reads input for service invocation. Turns properly formatted input into an instance of Values
* suitable for service invocation. Called before service invocation to provide input. If the
* transport is HTTP, and a Content-Encoding header was specified with the value "gzip" or "deflate",
* the stream is wrapped in a decompression stream.
*
* @param contentHandlerInput The input arguments for processing by the content handler.
* @throws IOException If an error occurs writing to the output stream.
*/
public void getInputValues(ContentHandlerInput contentHandlerInput) throws IOException {
if (startable.isStarted()) {
String contentType = contentHandlerInput.getInvokeState().getContentType();
if (!(contentType != null && EXCLUDED_CONTENT_TYPES.matcher(contentType).matches())) {
ProtocolInfoIf protocolInfoIf = contentHandlerInput.getInvokeState().getProtocolInfoIf();
if (protocolInfoIf instanceof HTTPState) {
HTTPState httpState = (HTTPState)protocolInfoIf;
String contentEncoding = HTTPStateHelper.getHeader(httpState, HttpHeader.CONTENT_ENCODING);
if (contentEncoding != null) {
if (contentEncoding.equalsIgnoreCase("gzip")) {
contentHandlerInput.setInputStream(new GZIPInputStream(contentHandlerInput.getInputStream(), InputOutputHelper.DEFAULT_BUFFER_SIZE));
HTTPStateHelper.removeHeader(httpState, HttpHeader.CONTENT_ENCODING);
} else if (contentEncoding.equalsIgnoreCase("deflate")) {
contentHandlerInput.setInputStream(new DeflaterInputStream(contentHandlerInput.getInputStream()));
HTTPStateHelper.removeHeader(httpState, HttpHeader.CONTENT_ENCODING);
}
}
}
}
}
}
示例5: testAvailable
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
/**
* @tests DeflaterInputStream#available()
*/
public void testAvailable() throws IOException {
byte[] buf = new byte[1024];
DeflaterInputStream dis = new DeflaterInputStream(is);
assertEquals(1, dis.available());
assertEquals(120, dis.read());
assertEquals(1, dis.available());
assertEquals(22, dis.read(buf, 0, 1024));
assertEquals(1, dis.available());
assertEquals(-1, dis.read());
assertEquals(0, dis.available());
dis.close();
try {
dis.available();
fail("should throw IOException");
} catch (IOException e) {
// expected
}
}
示例6: testRead
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
/**
* @tests DeflaterInputStream#read()
*/
public void testRead() throws IOException {
DeflaterInputStream dis = new DeflaterInputStream(is);
assertEquals(1, dis.available());
assertEquals(120, dis.read());
assertEquals(1, dis.available());
assertEquals(156, dis.read());
assertEquals(1, dis.available());
assertEquals(243, dis.read());
assertEquals(1, dis.available());
dis.close();
try {
dis.read();
fail("should throw IOException");
} catch (IOException e) {
// expected
}
}
示例7: writeEntryFromBuffer
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
/** Writes an entry with the given name, date and external file attributes from the buffer. */
private void writeEntryFromBuffer(ZipFileEntry entry, byte[] uncompressed) throws IOException {
CRC32 crc = new CRC32();
crc.update(uncompressed);
entry.setCrc(crc.getValue());
entry.setSize(uncompressed.length);
if (mode == OutputMode.FORCE_STORED) {
entry.setMethod(Compression.STORED);
entry.setCompressedSize(uncompressed.length);
writeEntry(entry, new ByteArrayInputStream(uncompressed));
} else {
ByteArrayOutputStream compressed = new ByteArrayOutputStream();
copyStream(new DeflaterInputStream(new ByteArrayInputStream(uncompressed), getDeflater()),
compressed);
entry.setMethod(Compression.DEFLATED);
entry.setCompressedSize(compressed.size());
writeEntry(entry, new ByteArrayInputStream(compressed.toByteArray()));
}
}
示例8: getContentReplayInputStream
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
/**
* Get a replay cued up for the 'content' (after all leading headers)
*
* @return A replay input stream.
* @throws IOException
*/
public InputStream getContentReplayInputStream() throws IOException {
InputStream entityStream = getEntityReplayInputStream();
if(StringUtils.isEmpty(contentEncoding)) {
return entityStream;
} else if ("gzip".equalsIgnoreCase(contentEncoding) || "x-gzip".equalsIgnoreCase(contentEncoding)) {
try {
return new GZIPInputStream(entityStream);
} catch (IOException ioe) {
logger.log(Level.WARNING,"gzip problem; using raw entity instead",ioe);
IOUtils.closeQuietly(entityStream); // close partially-read stream
return getEntityReplayInputStream();
}
} else if ("deflate".equalsIgnoreCase(contentEncoding)) {
return new DeflaterInputStream(entityStream);
} else if ("identity".equalsIgnoreCase(contentEncoding) || "none".equalsIgnoreCase(contentEncoding)) {
return entityStream;
} else {
// shouldn't be reached given check on setContentEncoding
logger.log(Level.INFO,"Unknown content-encoding '"+contentEncoding+"' declared; using raw entity instead");
return entityStream;
}
}
示例9: writeImpl
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
@SuppressWarnings("restriction")
@Override
public void writeImpl() {
final ByteArrayInputStream bais = new ByteArrayInputStream(this.packet);
final DeflaterInputStream deflaterInputStream = new DeflaterInputStream(bais);
byte[] defos;
try {
defos = sun.misc.IOUtils.readFully(deflaterInputStream, -1, true);
writeD(defos.length);
writeB(defos);
} catch (final IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例10: setValue
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
public void setValue(InputStreamHolder is, BlobFactory aBlobFactory) {
deserialBlob = null;
try (DeflaterInputStream inputStream = new DeflaterInputStream(is.getInputStream())) {
setBlob(aBlobFactory.createBlob(inputStream));
} catch (Exception e) {
String msg = "Impossible de mettre à jour le blob";
throw new RuntimeException(msg, e);
}
}
示例11: compress
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
private static byte[] compress(byte[] data) {
byte[] ret;
try (ByteArrayInputStream bis = new ByteArrayInputStream(data);
ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
ByteStreams.copy(new DeflaterInputStream(bis), bos);
ret = bos.toByteArray();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
return ret;
}
示例12: getInputStream
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
private InputStream getInputStream(HttpURLConnection urlConn) throws IOException {
InputStream is = urlConn.getInputStream();
String contentEncoding = urlConn.getContentEncoding();
if (contentEncoding == null) {
return is;
}
if ("gzip".equalsIgnoreCase(contentEncoding)) {
return new GZIPInputStream(is);
}
if ("deflate".equalsIgnoreCase(contentEncoding)) {
return new DeflaterInputStream(is);
}
// This should never happen
throw new IOException("Unsupported content encoding " + contentEncoding);
}
示例13: decompress
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
public static byte[] decompress(byte[] contentBytes) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
InputStream input = new DeflaterInputStream(new ByteArrayInputStream(contentBytes));
byte[] buf = new byte[1024];
int len = -1;
while ((len = input.read(buf)) > 0) {
out.write(buf, 0, len);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return out.toByteArray();
}
示例14: prepareForWriting
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
void prepareForWriting()
{
IOUtils.closeQuietly(dataWriter);
setItem(COSName.N, asDirectObject(COSInteger.get(counter)));
setItem(COSName.FIRST, asDirectObject(COSInteger.get(header.size())));
setItem(COSName.FILTER, asDirectObject(COSName.FLATE_DECODE));
this.filtered = new DeflaterInputStream(
new SequenceInputStream(new ByteArrayInputStream(header.toByteArray()),
new ByteArrayInputStream(data.toByteArray())));
this.header = null;
this.data = null;
}
示例15: testMark
import java.util.zip.DeflaterInputStream; //导入依赖的package包/类
/**
* @tests DeflaterInputStream#mark()
*/
public void testMark() throws IOException {
// mark do nothing
DeflaterInputStream dis = new DeflaterInputStream(is);
dis.mark(-1);
dis.mark(0);
dis.mark(1);
dis.close();
dis.mark(1);
}