Java 8 CheckedInputStream - 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 CheckedInputStream class.

This code example shows how to use the following methods:close, getChecksum
    private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
        DataTree dt = new DataTree();
        Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
        InputStream snapIS = new BufferedInputStream(new FileInputStream(
                snapFile));
        CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
        InputArchive ia = BinaryInputArchive.getArchive(crcIn);
        try { 
            snap.deserialize(dt, sessions, ia);
        } catch (IOException ie) {
            // we failed on the most recent snapshot 
            // must be incomplete 
            // try reading the next one 
            // after corrupting 
            snapIS.close();
            crcIn.close();
            throw ie;
        } 
 
        long checksum = crcIn.getChecksum().getValue();

7
CodeRank
This code example shows how to use the following methods:getChecksum, skip
	 * @tests java.util.zip.CheckedInputStream#skip(long) 
	 */ 
	public void test_skipJ() throws Exception { 
        // testing that the return by skip is valid 
        InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
        long skipValue = 5;
        assertEquals("the value returned by skip(n) is not the same as its parameter",
                skipValue, checkIn.skip(skipValue));
        checkIn.skip(skipValue);
        // ran JDK and found the checkSum value is 2235765342 
        // System.out.print(checkIn.getChecksum().getValue()); 
        assertEquals("checkSum value is not correct", 2235765342L, checkIn.getChecksum()
                .getValue());
        checkInput.close();
    } 
 
    public void test_read() throws Exception { 
        // testing that the return by skip is valid 
        InputStream checkInput = Support_Resources
6
CodeRank
This code example shows how to use the following methods:
        assertReadsFailWithIoException(new BufferedInputStream(null));
        assertReadsFailWithIoException(new BufferedInputStream(null, 1024));
    } 
 
    public void testCheckedInputStream() throws IOException { 
        assertReadsFailWithNullPointerException(new CheckedInputStream(null, new CRC32()));
    } 
 
    public void testCipherInputStream() throws IOException { 
        InputStream in = new CipherInputStream(null, new NullCipher());
        try { 
            in.read();
            fail();
        } catch (NullPointerException expected) {
        } 
 
        assertEquals(0, in.available());
 
        try { 
            in.close();
5
CodeRank
This code example shows how to use the following methods:
     * @throws IOException if the server instance could not be created 
     */ 
    public ForkServer(InputStream input, OutputStream output)
            throws IOException {
        this.input =
            new DataInputStream(new CheckedInputStream(input, this));
        this.output =
            new DataOutputStream(new CheckedOutputStream(output, this));
    } 
 
    public void run() { 
        try { 
            while (active) {
                active = false;
                Thread.sleep(5000);
            } 
            System.exit(0);
        } catch (InterruptedException e) {
        } 
    } 
4
CodeRank
This code example shows how to use the following methods:
     * 
     * @param in The uncompressed {@link InputStream}. 
     */ 
    public GZIPCompressorInputStream(InputStream in)
    { 
        super(new CheckedInputStream(in, new CRC32()), new Deflater(Deflater.DEFAULT_COMPRESSION, true));
        buffer = new Buffer();
    } 
 
    public int read(byte b[], int off, int len) throws IOException
    { 
        // Check if there are bytes left to be read from the internal buffer. This is used to provide the header 
        // or trailer, and always takes precedence. 
        int count;
        if (buffer.getByteCountRemainder() > 0)
        { 
            // Write data from the internal buffer into b. 
            count = Math.min(len, buffer.getByteCountRemainder());
            System.arraycopy(buffer.data, buffer.position, b, off, count);
 
4
CodeRank
This code example shows how to use the following methods:
    try { 
      InputStream is = new BufferedInputStream(fs.open(path));
      if (codec != null) {
        is = codec.createInputStream(is);
      } 
      in = new CheckedInputStream(is, crc);
      org.apache.commons.io.IOUtils.copy(in, new NullOutputStream());
    } finally { 
      org.apache.commons.io.IOUtils.closeQuietly(in);
    } 
    return crc.getValue();
  } 
 
  @Test
  public void testCopyFromLocalToDfs() throws Exception {
    Configuration conf = new Configuration(); 
    final FileSystem srcFs = FileSystem.getLocal(conf);
    final FileSystem destFs = FileSystem.getLocal(conf);
    final String namenode = destFs.getUri().toString();
    System.out.println("NN = " + namenode);
4
CodeRank
This code example shows how to use the following methods:
    try { 
      InputStream is = new BufferedInputStream(path.getFileSystem(config.getConfig()).open(path));
      if (config.getCodec() != null) {
        is = config.getCodec().createInputStream(is);
      } 
      in = new CheckedInputStream(is, crc);
      org.apache.commons.io.IOUtils.copy(in, new NullOutputStream());
    } finally { 
      org.apache.commons.io.IOUtils.closeQuietly(in);
    } 
    return crc.getValue();
  } 
 
  private Path getHdfsTargetPath(FileStatus srcFile) throws IOException {
    if (config.getDestDir() != null) {
      if (config.getCodec() != null) {
        return new Path(config.getDestDir(), srcFile.getPath().getName() + config.getCodec().getDefaultExtension());
      } else { 
        return new Path(config.getDestDir(), srcFile.getPath().getName());
      } 
4
CodeRank
This code example shows how to use the following methods:
            this.checksum = checksum;
        } 
 
        @Override 
        InputStream decorate(final InputStream wrapped) throws IOException {
            return new CheckedInputStream(wrapped, this.checksum);
        } 
 
    } 
 
} 
4
CodeRank
This code example shows how to use the following methods:
		// String absoluteName = f.getAbsolutePath(); 
		FileInputStream fis = null;
		boolean returnValue = false;
		try { 
			fis = new FileInputStream(f);
			final CheckedInputStream cis = new CheckedInputStream(fis,
					new CRC32());
			final ZipInputStream zis = new ZipInputStream(
					new BufferedInputStream(cis));
			final ZipEntry ze = zis.getNextEntry();
			returnValue = false;
 
			if (ze != null) {
				returnValue = true;
			} 
		} finally { 
			if (fis != null) {
				fis.close();
			} 
		} 
4
CodeRank
This code example shows how to use the following methods:getChecksum
    // read reamining bytes  
    byte[] headerData = new byte[SIZE-STATUS_BYTE_OFFSET]; 
    // no open a checked input stream ...  
    stream.readFully(headerData);
    // and now read it in via checked input stream 
    CheckedInputStream checkedInputStream = new CheckedInputStream(new ByteArrayInputStream(headerData),new CRC16());
    DataInputStream dataStream = new DataInputStream(checkedInputStream);
     
    _status = dataStream.readByte();
    _lastAccessTime = dataStream.readLong();
    _fingerprint = dataStream.readLong();
    _dataLength = dataStream.readInt();
     
    // now validate header checksum ...  
    if (checkedInputStream.getChecksum().getValue() != (long)checksumOnDisk) { 
      throw new IOException("Checksum failed while reading Item Header!");
    } 
  }     
   
} 
4
CodeRank
See Code Examples for Java 8 CheckedInputStream Methods: