Java 8 DeflaterInputStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DeflaterInputStream class.

This code example shows how to use the following methods:close, mark
    /** 
     * @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);
    } 
 
    /** 
     * @tests DeflaterInputStream#markSupported() 
     */ 
    public void testMarkSupported() throws IOException { 
        DeflaterInputStream dis = new DeflaterInputStream(is);
        assertFalse(dis.markSupported());
        dis.close();
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, read
    } 
 
    public void testReadExceptions() 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));
        try { 
            in.read(buffer, 0, 10);
            fail();
        } catch (IndexOutOfBoundsException expected) {
        } 
        try { 
            in.read(null, 0, 5);
            fail();
        } catch (NullPointerException expected) {
        } 
        try { 
            in.read(buffer, -1, 5);
            fail();
        } catch (IndexOutOfBoundsException expected) {

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:available, close, read
    /** 
     * @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 
        } 
    } 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, read
    } 
 
    public void testReadExceptions() 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));
        try { 
            in.read(buffer, 0, 10);
            fail();
        } catch (IndexOutOfBoundsException expected) {
        } 
        try { 
            in.read(null, 0, 5);
            fail();
        } catch (NullPointerException expected) {
        } 
        try { 
            in.read(buffer, -1, 5);
            fail();
        } catch (IndexOutOfBoundsException expected) {

5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
    } 
    if (name.endsWith(".zip")) {
      return new ZipInputStream(in);
    } 
    if (name.endsWith(".deflate")) {
      return new DeflaterInputStream(in);
    } 
    return in;
  } 
 
  /** 
   * @param in   stream to read and copy 
   * @param file file to write stream's contents to 
   * @throws IOException if the stream can't be read or the file can't be written 
   */ 
  public static void copyStreamToFile(InputStream in, File file) throws IOException {
    FileOutputStream out = new FileOutputStream(file);
    try { 
      ByteStreams.copy(in, out);
    } finally { 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
                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; 
        } 
    } 
     
    /** 
     * Return a short prefix of the presumed-textual content as a String. 
     *  
     * @param size max length of String to return  
     * @return String prefix, or empty String (with logged exception) on any error 
3
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
{ 
	public final static String COMPRESSION_TYPE_DEFLATE = "dfl"; 
 
	@Override 
	public InputStream compress(InputStream in) { 
		return new DeflaterInputStream(in); 
	} 
 
	@Override 
	public InputStream uncompress(InputStream in) { 
		return new InflaterInputStream(in); 
	} 
 
	@Override 
	public String getType() { 
		return COMPRESSION_TYPE_DEFLATE; 
	} 
} 
3
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
                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; 
        } 
    } 
     
    /** 
     * Return a short prefix of the presumed-textual content as a String. 
     *  
     * @param size max length of String to return  
     * @return String prefix, or empty String (with logged exception) on any error 
2
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 DeflaterInputStream Methods: