List of usage examples for java.util.zip CheckedOutputStream CheckedOutputStream
public CheckedOutputStream(OutputStream out, Checksum cksum)
From source file:org.apache.hadoop.mapred.TestShuffleHandler.java
private static void createIndexFile(File indexFile, Configuration conf) throws IOException { if (indexFile.exists()) { System.out.println("Deleting existing file"); indexFile.delete();/* ww w . j a va 2 s . c o m*/ } 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(); }
From source file:org.sakaiproject.metaobj.shared.mgt.impl.StructuredArtifactDefinitionManagerImpl.java
/** * This method will export a form into a stream. It has the ability to turn off checking * for the export form permission.// w w w. j a v a 2 s . co m * @param formId String * @param os OutputStream * @param checkPermission boolean * @throws IOException */ public void packageFormForExport(String formId, OutputStream os, boolean checkPermission) throws IOException { if (checkPermission) { getAuthzManager().checkPermission(SharedFunctionConstants.EXPORT_ARTIFACT_DEF, getToolId()); } CheckedOutputStream checksum = new CheckedOutputStream(os, new Adler32()); ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(checksum)); StructuredArtifactDefinitionBean bean = loadHome(formId); writeSADtoZip(bean, zos, ""); zos.finish(); zos.flush(); }
From source file:org.commoncrawl.service.listcrawler.CrawlHistoryManager.java
/** * append a ProxyCrawlHistoryItem to the active log * /*from www.j a v a 2s.c o m*/ * @param item * @throws IOException */ void appendItemToLog(ProxyCrawlHistoryItem item) throws IOException { try { // open the log file ... DataOutputStream logStream = new DataOutputStream(new FileOutputStream(getActiveLogFilePath(), true)); try { // reset crc calculator (single thread so no worries on synchronization) _crc16Out.reset(); // reset output stream _outputBuffer.reset(); // create checked stream CheckedOutputStream checkedStream = new CheckedOutputStream(_outputBuffer, _crc16Out); DataOutputStream dataOutputStream = new DataOutputStream(checkedStream); // write out item item.serialize(dataOutputStream, new BinaryProtocol()); dataOutputStream.flush(); // ok now write out sync,crc,length then data logStream.write(getLocalLogSyncBytes()); logStream.writeInt((int) checkedStream.getChecksum().getValue()); logStream.writeShort((short) _outputBuffer.getLength()); logStream.write(_outputBuffer.getData(), 0, _outputBuffer.getLength()); logStream.flush(); logStream.close(); logStream = null; // now we need to update the file header updateLogFileHeader(getActiveLogFilePath(), 1, LOG_ITEM_HEADER_SIZE + _outputBuffer.getLength()); URLFP fingerprint = URLUtils.getURLFPFromURL(item.getOriginalURL(), true); // update local log synchronized (_localLogItems) { if (fingerprint != null) { _localLogItems.put(fingerprint, item); } } ImmutableSet<CrawlList> lists = null; // and now walk lists updating them as necessary synchronized (_crawlLists) { lists = new ImmutableSet.Builder<CrawlList>().addAll(_crawlLists.values()).build(); } for (CrawlList list : lists) { try { list.updateItemState(fingerprint, item); } catch (Exception e) { // ok, IF an error occurs updating the list metadata.. we need to // coninue along. // it is critical for this thread to not die in such a circumstane LOG.fatal("Error Updating List(" + list.getListId() + "):" + CCStringUtils.stringifyException(e)); System.out.println("Exception in List Update(" + list.getListId() + "):" + CCStringUtils.stringifyException(e)); } } } finally { if (logStream != null) { logStream.close(); } } } finally { } }
From source file:org.openmrs.module.sync.SyncUtil.java
public static byte[] compress(String content) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); CheckedOutputStream cos = new CheckedOutputStream(baos, new CRC32()); GZIPOutputStream zos = new GZIPOutputStream(new BufferedOutputStream(cos)); IOUtils.copy(new ByteArrayInputStream(content.getBytes()), zos); return baos.toByteArray(); }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String Zip(String zipFileName, String srcName) { String fixedZipFileName = fixFileName(zipFileName); String fixedSrcName = fixFileName(srcName); String sRet = ""; try {/* ww w .j ava2 s . c om*/ FileOutputStream dest = new FileOutputStream(fixedZipFileName); CheckedOutputStream checksum = new CheckedOutputStream(dest, new Adler32()); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(checksum)); out.setMethod(ZipOutputStream.DEFLATED); sRet += AddFilesToZip(out, fixedSrcName, ""); out.close(); System.out.println("checksum: " + checksum.getChecksum().getValue()); sRet += "checksum: " + checksum.getChecksum().getValue(); } catch (Exception e) { e.printStackTrace(); } return (sRet); }