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

This code example shows how to use the following methods:flush, getChecksum
        assertEquals("entry name", entryName, entry.getName());
        assertTrue("entry can't be read", zip.canReadEntryData(entry));
        assertEquals("method", ZipMethod.IMPLODING.getCode(), entry.getMethod());
 
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        CheckedOutputStream out = new CheckedOutputStream(bout, new CRC32());
        IOUtils.copy(zip.getInputStream(entry), out);
 
        out.flush();
 
        assertEquals("CRC32", entry.getCrc(), out.getChecksum().getValue());
        zip.close();
    } 
 
    public void testArchiveWithImplodeCompression4K2Trees() throws IOException {
        testArchiveWithImplodeCompression("target/test-classes/archives/imploding-4Kdict-2trees.zip", "HEADER.TXT"); 
    } 
 
    public void testArchiveWithImplodeCompression8K3Trees() throws IOException {
        testArchiveWithImplodeCompression("target/test-classes/archives/imploding-8Kdict-3trees.zip", "LICENSE.TXT"); 
6
CodeRank
This code example shows how to use the following methods:getChecksum
 
    buf.writeLong(message.offset());                      // event offset
                                                          // event length 
    ChannelBufferOutputStream cbos = new ChannelBufferOutputStream(buf);
    CheckedOutputStream eventChk =
        new CheckedOutputStream(cbos, new PureJavaCrc32());
    serializer.open(eventChk);
    serializer.serialize(message.key());
    serializer.serialize(message.value());
    serializer.close(); 
 
    int end = buf.writerIndex();    
    int len =  end - (crcIndex + 4 + 4);
    buf.writerIndex(crcIndex);
    buf.writeInt((int)eventChk.getChecksum().getValue()); // checksum
    buf.writeInt(len);                                    // payload length
    buf.writerIndex(end);
    return buf;
  } 
 
5
CodeRank
This code example shows how to use the following methods:
   * Creates a new {@link OutputStreamIndexOutput} with the given buffer size.  
   * @param bufferSize the buffer size in bytes used to buffer writes internally. 
   * @throws IllegalArgumentException if the given buffer size is less or equal to <tt>0</tt> 
   */ 
  public OutputStreamIndexOutput(OutputStream out, int bufferSize) {
    this.os = new BufferedOutputStream(new CheckedOutputStream(out, crc), bufferSize);
  } 
 
  @Override 
  public final void writeByte(byte b) throws IOException {
    os.write(b);
    bytesWritten++;
  } 
   
  @Override 
  public final void writeBytes(byte[] b, int offset, int length) throws IOException {
    os.write(b, offset, length);
    bytesWritten += length;
  } 
 
5
CodeRank
This code example shows how to use the following methods:getChecksum
 
    buf.writeLong(message.offset());                      // event offset
                                                          // event length 
    ChannelBufferOutputStream cbos = new ChannelBufferOutputStream(buf);
    CheckedOutputStream eventChk =
        new CheckedOutputStream(cbos, new PureJavaCrc32());
    serializer.open(eventChk);
    serializer.serialize(message.key());
    serializer.serialize(message.value());
    serializer.close(); 
 
    int end = buf.writerIndex();    
    int len =  end - (crcIndex + 4 + 4);
    buf.writerIndex(crcIndex);
    buf.writeInt((int)eventChk.getChecksum().getValue()); // checksum
    buf.writeInt(len);                                    // payload length
    buf.writerIndex(end);
    return buf;
  } 
 
5
CodeRank
This code example shows how to use the following methods:
            this(new FileOutputStream(zipFile));
        } 
 
        public ZipFileWriter(FileOutputStream zipFile) throws FileNotFoundException {
            FileOutputStream fos = zipFile;
            CheckedOutputStream checksum = new CheckedOutputStream(fos, new Adler32());
            this.output = new ZipOutputStream(new BufferedOutputStream(checksum));
        } 
 
        public void addFile(String fileName) throws FileNotFoundException, IOException {
            FileInputStream fis = new FileInputStream(fileName);
            int size = 0;
            byte[] buffer = new byte[1024];
            File file = new File(fileName);
            ZipEntry zipEntry = new ZipEntry(file.getName());
            this.output.putNextEntry(zipEntry);
            while ((size = fis.read(buffer, 0, buffer.length)) > 0) {
                this.output.write(buffer, 0, size);
            } 
            this.output.closeEntry();
4
CodeRank
This code example shows how to use the following methods:
    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) {
        } 
    } 
 
    public void processRequests() { 
4
CodeRank
This code example shows how to use the following methods:write
        Murmur3F murmur3F = new Murmur3F();
        murmur3F.update(content);
        String hash = murmur3F.getValueHexString();
 
        murmur3F.reset();
        CheckedOutputStream out = new CheckedOutputStream(new ByteArrayOutputStream(), murmur3F);
        out.write(content);
        Assert.assertEquals(hash, murmur3F.getValueHexString());
 
        murmur3F.reset();
        CheckedInputStream in = new CheckedInputStream(new ByteArrayInputStream(content), murmur3F);
        IoUtils.readAllBytes(in);
        Assert.assertEquals(hash, murmur3F.getValueHexString());
    } 
 
} 
4
CodeRank
This code example shows how to use the following methods:
			try { 
				dest = new FileOutputStream(zipFileLocation);
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} 
			checksum = new CheckedOutputStream(dest, new Adler32());
			out = new ZipOutputStream(new 
					BufferedOutputStream(checksum));
		 
	} 
	 
	/** 
	 * Adds file to Zip. 
	 * 
	 * @param filePath the file path 
	 * @throws IOException Signals that an I/O exception has occurred. 
	 */ 
	public void add(String filePath) throws IOException {
		 
		byte data[] = new byte[BUFFER];
4
CodeRank
This code example shows how to use the following methods:
    private final ObjectOutputStream out;
    private static final Object MARKER = new Marker();
 
    public CheckedSender(OutputStream out) throws IOException {
        this.out = new ObjectOutputStream(
                new CheckedOutputStream(out, checksum));
    } 
 
    public synchronized void sendMessage(Object msg) throws IOException {
        out.writeObject(MARKER);
        checksum.reset();
        out.writeObject(msg);
        out.writeLong(checksum.getValue());
        out.reset();
        out.flush();
    } 
} 
4
CodeRank
This code example shows how to use the following methods:
     * @throws Exception  
     */   
    public static void compress(File srcFile, File destFile) throws Exception {  
   
        // 对输出文件做CRC32校验   
        CheckedOutputStream cos = new CheckedOutputStream(new FileOutputStream(  
                destFile), new CRC32());  
   
        ZipOutputStream zos = new ZipOutputStream(cos);  
   
        compress(srcFile, zos, BASE_DIR);  
   
        zos.flush();  
        zos.close();  
    }   
   
    /**  
     * 压缩文件  
     *   
     * @param srcFile  
4
CodeRank
See Code Examples for Java 8 CheckedOutputStream Methods: