List of usage examples for java.util.zip GZIPInputStream read
public int read() throws IOException
From source file:edu.harvard.iq.dvn.ingest.dsb.SubsettableFileChecker.java
/** * test this byte buffer against R data file * *///from ww w . java2 s . c om public String testRDAformat(MappedByteBuffer buff) { String result = null; buff.rewind(); boolean DEBUG = false; if (DEBUG) { out.println("applying the RData test\n"); out.println("buffer capacity=" + buff.capacity()); } if (DEBUG) { byte[] rawhdr = new byte[4]; buff.get(rawhdr, 0, 4); for (int j = 0; j < 4; j++) { out.printf("%02X ", rawhdr[j]); } out.println(); buff.rewind(); } // get the first 4 bytes as an int and check its value; // if it is 0x1F8B0800, then gunzip and its first 4 bytes int magicNumber = buff.getInt(); if (DEBUG) { out.println("magicNumber in decimal =" + magicNumber); out.println("in binary=" + Integer.toBinaryString(magicNumber)); out.println("in oct=" + Integer.toOctalString(magicNumber)); out.println("in hex=" + Integer.toHexString(magicNumber)); } try { if (magicNumber == 0x1F8B0800) { if (DEBUG) { out.println("magicNumber is GZIP"); } // gunzip the first 5 bytes and check their bye-pattern // get gzip buffer size int gzip_buffer_size = this.getGzipBufferSize(buff); byte[] hdr = new byte[gzip_buffer_size]; buff.get(hdr, 0, gzip_buffer_size); GZIPInputStream gzin = new GZIPInputStream(new ByteArrayInputStream(hdr)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < RDA_HEADER_SIZE; i++) { sb.append(String.format("%02X", gzin.read())); } String fisrt5bytes = sb.toString(); result = this.checkUncompressedFirst5bytes(fisrt5bytes); // end of compressed case } else { // uncompressed case? if (DEBUG) { out.println("magicNumber is not GZIP:" + magicNumber); out.println("test as an uncompressed RData file"); } buff.rewind(); byte[] uchdr = new byte[5]; buff.get(uchdr, 0, 5); StringBuilder sb = new StringBuilder(); for (int i = 0; i < uchdr.length; i++) { sb.append(String.format("%02X", uchdr[i])); } String fisrt5bytes = sb.toString(); result = this.checkUncompressedFirst5bytes(fisrt5bytes); // end of uncompressed case } } catch (IOException ex) { ex.printStackTrace(); } return result; }
From source file:edu.harvard.iq.dataverse.ingest.IngestableDataChecker.java
/** * test this byte buffer against R data file * *//*from w ww .jav a 2s . c om*/ public String testRDAformat(MappedByteBuffer buff) { String result = null; buff.rewind(); if (buff.capacity() < 4) { return null; } boolean DEBUG = false; if (DEBUG) { out.println("applying the RData test\n"); out.println("buffer capacity=" + buff.capacity()); } if (DEBUG) { byte[] rawhdr = new byte[4]; buff.get(rawhdr, 0, 4); for (int j = 0; j < 4; j++) { out.printf("%02X ", rawhdr[j]); } out.println(); buff.rewind(); } // get the first 4 bytes as an int and check its value; // if it is 0x1F8B0800, then gunzip and its first 4 bytes int magicNumber = buff.getInt(); if (DEBUG) { out.println("magicNumber in decimal =" + magicNumber); out.println("in binary=" + Integer.toBinaryString(magicNumber)); out.println("in oct=" + Integer.toOctalString(magicNumber)); out.println("in hex=" + Integer.toHexString(magicNumber)); } try { if (magicNumber == 0x1F8B0800) { if (DEBUG) { out.println("magicNumber is GZIP"); } // gunzip the first 5 bytes and check their bye-pattern // get gzip buffer size int gzip_buffer_size = this.getGzipBufferSize(buff); byte[] hdr = new byte[gzip_buffer_size]; buff.get(hdr, 0, gzip_buffer_size); GZIPInputStream gzin = new GZIPInputStream(new ByteArrayInputStream(hdr)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < RDA_HEADER_SIZE; i++) { sb.append(String.format("%02X", gzin.read())); } String fisrt5bytes = sb.toString(); result = this.checkUncompressedFirst5bytes(fisrt5bytes); // end of compressed case } else { // uncompressed case? if (DEBUG) { out.println("magicNumber is not GZIP:" + magicNumber); out.println("test as an uncompressed RData file"); } buff.rewind(); byte[] uchdr = new byte[5]; buff.get(uchdr, 0, 5); StringBuilder sb = new StringBuilder(); for (int i = 0; i < uchdr.length; i++) { sb.append(String.format("%02X", uchdr[i])); } String fisrt5bytes = sb.toString(); result = this.checkUncompressedFirst5bytes(fisrt5bytes); // end of uncompressed case } } catch (IOException ex) { ex.printStackTrace(); } return result; }