java.util.zip.CheckedOutputStream Java Examples
The following examples show how to use
java.util.zip.CheckedOutputStream.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompressedXContent.java From crate with Apache License 2.0 | 6 votes |
/** * Create a {@link CompressedXContent} out of a {@link ToXContent} instance. */ public CompressedXContent(ToXContent xcontent, XContentType type, ToXContent.Params params) throws IOException { BytesStreamOutput bStream = new BytesStreamOutput(); OutputStream compressedStream = CompressorFactory.COMPRESSOR.streamOutput(bStream); CRC32 crc32 = new CRC32(); try (OutputStream checkedStream = new CheckedOutputStream(compressedStream, crc32)) { try (XContentBuilder builder = XContentFactory.contentBuilder(type, checkedStream)) { builder.startObject(); xcontent.toXContent(builder, params); builder.endObject(); } } this.bytes = BytesReference.toBytes(bStream.bytes()); this.crc32 = (int) crc32.getValue(); assertConsistent(); }
Example #2
Source File: ZipMeUp.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #3
Source File: ZipMeUp.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #4
Source File: ZipUtils.java From litchi with Apache License 2.0 | 6 votes |
public static boolean compress(String srcFilePath, String destFilePath) { File src = new File(srcFilePath); if (!src.exists()) { throw new RuntimeException(srcFilePath + "not exist"); } File zipFile = new File(destFilePath); try { FileOutputStream fos = new FileOutputStream(zipFile); CheckedOutputStream cos = new CheckedOutputStream(fos, new CRC32()); ZipOutputStream zos = new ZipOutputStream(cos); String baseDir = ""; compressbyType(src, zos, baseDir); zos.close(); return true; } catch (Exception e) { LOGGER.error("", e); } return false; }
Example #5
Source File: FileDownloadServlet.java From EasyML with Apache License 2.0 | 6 votes |
/** * Compressed file or directory * * @param srcPath The address of the file or folder * @param zipFilePath The address of the compressed package */ public static void zipFiles(String srcPath,String zipFilePath) { File file = new File(srcPath); if (!file.exists()) throw new RuntimeException(srcPath + "not exist!"); try { FileOutputStream fileOutputStream = new FileOutputStream(zipFilePath); CheckedOutputStream cos = new CheckedOutputStream(fileOutputStream, new CRC32()); ZipOutputStream out = new ZipOutputStream(cos); String baseDir=""; zip(file,out,baseDir); out.close(); } catch (Exception e) { throw new RuntimeException(e); } }
Example #6
Source File: ZipMeUp.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #7
Source File: ZipMeUp.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #8
Source File: ZipMeUp.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #9
Source File: ZipMeUp.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #10
Source File: TestShuffleHandler.java From hadoop with Apache License 2.0 | 6 votes |
private static void createIndexFile(File indexFile, Configuration conf) throws IOException { if (indexFile.exists()) { System.out.println("Deleting existing file"); indexFile.delete(); } indexFile.createNewFile(); FSDataOutputStream output = FileSystem.getLocal(conf).getRaw().append( new Path(indexFile.getAbsolutePath())); Checksum crc = new PureJavaCrc32(); crc.reset(); CheckedOutputStream chk = new CheckedOutputStream(output, crc); String msg = "Writing new index file. This file will be used only " + "for the testing."; chk.write(Arrays.copyOf(msg.getBytes(), MapTask.MAP_OUTPUT_INDEX_RECORD_LENGTH)); output.writeLong(chk.getChecksum().getValue()); output.close(); }
Example #11
Source File: ZipMeUp.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #12
Source File: ZipMeUp.java From hottub with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #13
Source File: ZipMeUp.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #14
Source File: ZipMeUp.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #15
Source File: FileUtil.java From FEBS-Cloud with Apache License 2.0 | 6 votes |
/** * 压缩文件或目录 * * @param fromPath 待压缩文件或路径 * @param toPath 压缩文件,如 xx.zip */ public static void compress(String fromPath, String toPath) throws IOException { File fromFile = new File(fromPath); File toFile = new File(toPath); if (!fromFile.exists()) { throw new FileNotFoundException(fromPath + "不存在!"); } try ( FileOutputStream outputStream = new FileOutputStream(toFile); CheckedOutputStream checkedOutputStream = new CheckedOutputStream(outputStream, new CRC32()); ZipOutputStream zipOutputStream = new ZipOutputStream(checkedOutputStream) ) { String baseDir = ""; compress(fromFile, zipOutputStream, baseDir); } }
Example #16
Source File: LocalStore.java From hadoop-gpu with Apache License 2.0 | 6 votes |
/** * Compress a text file using the ZIP compressing algorithm. * * @param filename the path to the file to be compressed */ public static void zipCompress(String filename) throws IOException { FileOutputStream fos = new FileOutputStream(filename + COMPRESSION_SUFFIX); CheckedOutputStream csum = new CheckedOutputStream(fos, new CRC32()); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(csum)); out.setComment("Failmon records."); BufferedReader in = new BufferedReader(new FileReader(filename)); out.putNextEntry(new ZipEntry(new File(filename).getName())); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.finish(); out.close(); }
Example #17
Source File: LocalStore.java From RDFS with Apache License 2.0 | 6 votes |
/** * Compress a text file using the ZIP compressing algorithm. * * @param filename the path to the file to be compressed */ public static void zipCompress(String filename) throws IOException { FileOutputStream fos = new FileOutputStream(filename + COMPRESSION_SUFFIX); CheckedOutputStream csum = new CheckedOutputStream(fos, new CRC32()); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(csum)); out.setComment("Failmon records."); BufferedReader in = new BufferedReader(new FileReader(filename)); out.putNextEntry(new ZipEntry(new File(filename).getName())); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.finish(); out.close(); }
Example #18
Source File: ChecksumStreamTest.java From essentials with Apache License 2.0 | 6 votes |
@Test public void testChecksumStreams() throws IOException { byte[] content = new byte[33333]; new Random().nextBytes(content); 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()); }
Example #19
Source File: BlockCompressedRecordFile.java From lsmtree with Apache License 2.0 | 6 votes |
private void flushBuffer() throws IOException { final UnsafeByteArrayOutputStream compressedBuffer = new UnsafeByteArrayOutputStream(blockSize+4*numRecords); final CheckedOutputStream checksumStream = new CheckedOutputStream(compressedBuffer, new Adler32()); final DataOutputStream compressorStream = new DataOutputStream(codec.createOutputStream(checksumStream)); compressorStream.writeInt(numRecords); for (int i = 0; i < numRecords; i++) { VIntUtils.writeVInt((OutputStream)compressorStream, lengthBuffer[i]); } compressorStream.write(currentBlockBytes.getByteArray(), 0, currentBlockBytes.size()); compressorStream.close(); out.writeInt(compressedBuffer.size()); final int checksum = (int)checksumStream.getChecksum().getValue(); out.writeInt(checksum); out.write(compressedBuffer.getByteArray(), 0, compressedBuffer.size()); currentBlockBytes.reset(); numRecords = 0; final int padLength = (int)(pad-out.position()%pad); if (padLength != pad) { for (int i = 0; i < padLength; i++) { out.writeByte(0); } } blockAddress = out.position()<<shift; }
Example #20
Source File: IndexEncoder.java From LocalGSMLocationProvider with Apache License 2.0 | 6 votes |
public void encode(OutputStream out) throws IOException { java.util.zip.CRC32 crc32 = new java.util.zip.CRC32(); CheckedOutputStream outChecked = new CheckedOutputStream(out, crc32); // Index Indicator outChecked.write(0x00); // Number of Records EncoderUtil.encodeVLI(outChecked, recordCount); // List of Records for (Iterator i = records.iterator(); i.hasNext(); ) { IndexRecord record = (IndexRecord)i.next(); EncoderUtil.encodeVLI(outChecked, record.unpadded); EncoderUtil.encodeVLI(outChecked, record.uncompressed); } // Index Padding for (int i = getIndexPaddingSize(); i > 0; --i) outChecked.write(0x00); // CRC32 long value = crc32.getValue(); for (int i = 0; i < 4; ++i) out.write((byte)(value >>> (i * 8))); }
Example #21
Source File: ZipMeUp.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #22
Source File: ZipMeUp.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #23
Source File: IndexEncoder.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
public void encode(OutputStream out) throws IOException { java.util.zip.CRC32 crc32 = new java.util.zip.CRC32(); CheckedOutputStream outChecked = new CheckedOutputStream(out, crc32); // Index Indicator outChecked.write(0x00); // Number of Records EncoderUtil.encodeVLI(outChecked, recordCount); // List of Records for (IndexRecord record : records) { EncoderUtil.encodeVLI(outChecked, record.unpadded); EncoderUtil.encodeVLI(outChecked, record.uncompressed); } // Index Padding for (int i = getIndexPaddingSize(); i > 0; --i) outChecked.write(0x00); // CRC32 long value = crc32.getValue(); for (int i = 0; i < 4; ++i) out.write((byte)(value >>> (i * 8))); }
Example #24
Source File: ZipMeUp.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
static byte[] getManifestAsBytes(int nchars) throws IOException { crc.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, crc); PrintStream ps = new PrintStream(cos); ps.println("Manifest-Version: 1.0"); ps.print("Main-Class: "); for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { ps.print(i%10); } ps.println(SOME_KLASS); cos.flush(); cos.close(); ps.close(); return baos.toByteArray(); }
Example #25
Source File: TestShuffleHandler.java From big-c with Apache License 2.0 | 6 votes |
private static void createIndexFile(File indexFile, Configuration conf) throws IOException { if (indexFile.exists()) { System.out.println("Deleting existing file"); indexFile.delete(); } indexFile.createNewFile(); FSDataOutputStream output = FileSystem.getLocal(conf).getRaw().append( new Path(indexFile.getAbsolutePath())); Checksum crc = new PureJavaCrc32(); crc.reset(); CheckedOutputStream chk = new CheckedOutputStream(output, crc); String msg = "Writing new index file. This file will be used only " + "for the testing."; chk.write(Arrays.copyOf(msg.getBytes(), MapTask.MAP_OUTPUT_INDEX_RECORD_LENGTH)); output.writeLong(chk.getChecksum().getValue()); output.close(); }
Example #26
Source File: TacCompressUtils.java From tac with MIT License | 5 votes |
/** * compress * * @param srcFile * @param destFile * @throws Exception */ public static void compress(File srcFile, File destFile) throws Exception { // CRC32 check CheckedOutputStream cos = new CheckedOutputStream(new FileOutputStream( destFile), new CRC32()); ZipOutputStream zos = new ZipOutputStream(cos); zos.setComment(new String("comment")); compress(srcFile, zos, BASE_DIR); zos.flush(); zos.close(); }
Example #27
Source File: ArscFileGenerator.java From Baffle with MIT License | 5 votes |
public CRC32 createObfuscateFile( ArscData data, StringBlock tableBlock, StringBlock keyBlock, File file ) throws IOException { FileOutputStream fileOutputStream = new FileOutputStream(file); CRC32 cksum = new CRC32(); CheckedOutputStream checkedOutputStream = new CheckedOutputStream(fileOutputStream, cksum); LEDataOutputStream out = new LEDataOutputStream(checkedOutputStream); int tableStrChange = data.getmTableStrings().getSize() - tableBlock.getSize(); int keyStrChange = data.getmSpecNames().getSize() - keyBlock.getSize(); data.getmHeader().chunkSize -=(tableStrChange + keyStrChange); data.getmHeader().write(out); out.writeInt(1); tableBlock.write(out); data.getmPkgHeader().header.chunkSize -=keyStrChange; data.getmPkgHeader().write(out); data.getTypeNames().write(out); keyBlock.write(out); byte[] buff = new byte[1024]; FileInputStream in = new FileInputStream(data.getFile()); in.skip(data.getmResIndex()); int len ; while(((len = in.read(buff)) != -1)){ out.write(buff , 0 , len); } in.close(); out.close(); checkedOutputStream.close(); fileOutputStream.close(); return cksum; }
Example #28
Source File: CompressedXContent.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Create a {@link CompressedXContent} out of a {@link ToXContent} instance. */ public CompressedXContent(ToXContent xcontent, XContentType type, ToXContent.Params params) throws IOException { BytesStreamOutput bStream = new BytesStreamOutput(); OutputStream compressedStream = CompressorFactory.defaultCompressor().streamOutput(bStream); CRC32 crc32 = new CRC32(); OutputStream checkedStream = new CheckedOutputStream(compressedStream, crc32); try (XContentBuilder builder = XContentFactory.contentBuilder(type, checkedStream)) { builder.startObject(); xcontent.toXContent(builder, params); builder.endObject(); } this.bytes = bStream.bytes().toBytes(); this.crc32 = (int) crc32.getValue(); assertConsistent(); }
Example #29
Source File: DocViewFormat.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** internally formats the given file and computes their checksum * * @param file the file * @param original checksum of the original file * @param formatted checksum of the formatted file * @return the formatted bytes * @throws IOException if an error occurs */ private byte[] format(File file, Checksum original, Checksum formatted) throws IOException { try (InputStream in = new CheckedInputStream(new BufferedInputStream(new FileInputStream(file)), original)) { @SuppressWarnings("resource") ByteArrayOutputStream buffer = formattingBuffer != null ? formattingBuffer.get() : null; if (buffer == null) { buffer = new ByteArrayOutputStream(); formattingBuffer = new WeakReference<>(buffer); } else { buffer.reset(); } try (OutputStream out = new CheckedOutputStream(buffer, formatted); FormattingXmlStreamWriter writer = FormattingXmlStreamWriter.create(out, format)) { // cannot use XMlStreamReader due to comment handling: // https://stackoverflow.com/questions/15792007/why-does-xmlstreamreader-staxsource-strip-comments-from-xml TransformerFactory tf = TransformerFactory.newInstance(); tf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true); SAXSource saxSource = new SAXSource(new InputSource(in)); SAXParserFactory sf = SAXParserFactory.newInstance(); sf.setNamespaceAware(true); sf.setFeature("http://xml.org/sax/features/namespace-prefixes", true); sf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true); saxSource.setXMLReader(new NormalizingSaxFilter(sf.newSAXParser().getXMLReader())); Transformer t = tf.newTransformer(); StAXResult result = new StAXResult(writer); t.transform(saxSource, result); } return buffer.toByteArray(); } catch (TransformerException | XMLStreamException | FactoryConfigurationError | ParserConfigurationException | SAXException ex) { throw new IOException(ex); } }
Example #30
Source File: ArscData.java From Baffle with MIT License | 5 votes |
public CRC32 createObfuscateFile(StringBlock tableBlock, StringBlock keyBlock, File file ) throws IOException { FileOutputStream fileOutputStream = new FileOutputStream(file); CRC32 cksum = new CRC32(); CheckedOutputStream checkedOutputStream = new CheckedOutputStream(fileOutputStream, cksum); LEDataOutputStream out = new LEDataOutputStream(checkedOutputStream); int tableStrChange = getmTableStrings().getSize() - tableBlock.getSize(); int keyStrChange = getmSpecNames().getSize() - keyBlock.getSize(); getmHeader().chunkSize -=(tableStrChange + keyStrChange); getmHeader().write(out); out.writeInt(1); tableBlock.write(out); getmPkgHeader().header.chunkSize -=keyStrChange; getmPkgHeader().write(out); getTypeNames().write(out); keyBlock.write(out); byte[] buff = new byte[1024]; FileInputStream in = new FileInputStream(getFile()); in.skip(getmResIndex()); int len ; while(((len = in.read(buff)) != -1)){ out.write(buff , 0 , len); } in.close(); out.close(); checkedOutputStream.close(); fileOutputStream.close(); return cksum; }