當前位置: 首頁>>代碼示例>>Java>>正文


Java CheckedInputStream類代碼示例

本文整理匯總了Java中java.util.zip.CheckedInputStream的典型用法代碼示例。如果您正苦於以下問題:Java CheckedInputStream類的具體用法?Java CheckedInputStream怎麽用?Java CheckedInputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CheckedInputStream類屬於java.util.zip包,在下文中一共展示了CheckedInputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: calculateChecksum

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
private long calculateChecksum(URL layer) {
    if (layer == null) {
        return -1;
    }
    try {
        InputStream is = layer.openStream();
        try {
            CheckedInputStream cis = new CheckedInputStream(is, new CRC32());
            // Compute the CRC32 checksum
            byte[] buf = new byte[1024];
            while (cis.read(buf) >= 0) {
            }
            cis.close();
            return cis.getChecksum().getValue();
        } finally {
            is.close();
        }
    } catch (IOException e) {
        return -1;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:JaveleonModuleReloader.java

示例2: getCheckSum

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
/** return if checksum matches for a snapshot **/
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();
    long val = ia.readLong("val");
    snapIS.close();
    crcIn.close();
    return (val != checksum);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:27,代碼來源:CRCTest.java

示例3: getCRC32

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
public static long getCRC32(String File)
{
	try
	{
		FileInputStream fis = new FileInputStream(File);
		CRC32 crc = new CRC32();
		CheckedInputStream cis = new CheckedInputStream(fis, crc);
		while (cis.read(THROWAWAY_BUFFER, 0, THROWAWAY_BUFFER.length) != -1)
			;

		cis.close();
		return crc.getValue();
	}
	catch (Exception e)
	{
		e.printStackTrace();
		return -1;
	}
}
 
開發者ID:TheRemote,項目名稱:Spark,代碼行數:20,代碼來源:SparkUtil.java

示例4: getApkFileChecksum

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
private static long getApkFileChecksum(Context context) {
    String apkPath = context.getPackageCodePath();
    Long chksum = null;
    try {
        // Open the file and build a CRC32 checksum.
        FileInputStream fis = new FileInputStream(new File(apkPath));
        CRC32 chk = new CRC32();
        CheckedInputStream cis = new CheckedInputStream(fis, chk);
        byte[] buff = new byte[80];
        while (cis.read(buff) >= 0) ;
        chksum = chk.getValue();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return chksum;
}
 
開發者ID:Catherine22,項目名稱:SecuritySample,代碼行數:17,代碼來源:Utils.java

示例5: Reader

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
/**
 * Construct the reader
 * @param in The stream to read from.
 * @param logVersion The version of the data coming from the stream.
 */
public Reader(DataInputStream in, StreamLimiter limiter, int logVersion) {
  this.logVersion = logVersion;
  if (NameNodeLayoutVersion.supports(
      LayoutVersion.Feature.EDITS_CHESKUM, logVersion)) {
    this.checksum = DataChecksum.newCrc32();
  } else {
    this.checksum = null;
  }
  // It is possible that the logVersion is actually a future layoutversion
  // during the rolling upgrade (e.g., the NN gets upgraded first). We
  // assume future layout will also support length of editlog op.
  this.supportEditLogLength = NameNodeLayoutVersion.supports(
      NameNodeLayoutVersion.Feature.EDITLOG_LENGTH, logVersion)
      || logVersion < NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION;

  if (this.checksum != null) {
    this.in = new DataInputStream(
        new CheckedInputStream(in, this.checksum));
  } else {
    this.in = in;
  }
  this.limiter = limiter;
  this.cache = new OpInstanceCache();
  this.maxOpSize = DFSConfigKeys.DFS_NAMENODE_MAX_OP_SIZE_DEFAULT;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:31,代碼來源:FSEditLogOp.java

示例6: validateFileWithChecksum

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
private static void validateFileWithChecksum(FileSystem fs, Path filePath, BackupFileInfo backupFileInfo) throws IOException {
  final CheckedInputStream cin = new CheckedInputStream(fs.open(filePath), new CRC32());
  final BufferedReader reader = new BufferedReader(new InputStreamReader(cin));
  final ObjectMapper objectMapper = new ObjectMapper();
  String line;
  long records = 0;
  // parse records just to make sure formatting is correct
  while ((line = reader.readLine()) != null) {
    objectMapper.readValue(line, BackupRecord.class);
    ++records;
  }
  cin.close();
  long found = cin.getChecksum().getValue();
  if (backupFileInfo.getChecksum() != found) {
    throw new IOException(format("Corrupt backup data file %s. Expected checksum %x, found %x", filePath, backupFileInfo.getChecksum(), found));
  }
  if (backupFileInfo.getRecords() != records) {
    throw new IOException(format("Corrupt backup data file %s. Expected records %x, found %x", filePath, backupFileInfo.getRecords(), records));
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:21,代碼來源:BackupRestoreUtil.java

示例7: createPackageChecksum

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
public static String createPackageChecksum(String fp) throws IOException {
    Path path = Paths.get(fp);
    try (CheckedInputStream is = new CheckedInputStream(Files.newInputStream(path), new Adler32())) {
        byte[] buf = new byte[1024*1024];
        int total = 0;
        int c = 0;
        while (total < 100*1024*1024 && (c = is.read(buf)) >= 0) {
            total += c;
        }

        ByteBuffer bb = ByteBuffer.allocate(Long.BYTES);
        bb.putLong(path.toFile().length());
        buf = bb.array();
        is.getChecksum().update(buf, 0, buf.length);
        return Long.toHexString(is.getChecksum().getValue());
    }
}
 
開發者ID:PlayPen,項目名稱:playpen-core,代碼行數:18,代碼來源:AuthUtils.java

示例8: getSFVFile

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
private SFVInfo getSFVFile(Slave slave, String path) throws IOException {
	BufferedReader reader = null;
	CRC32 checksum = null;
	try {
		File file = slave.getRoots().getFile(path);
		checksum = new CRC32();
		reader = new BufferedReader(new InputStreamReader(new CheckedInputStream(new FileInputStream(file), checksum)));
		SFVInfo sfvInfo = SFVInfo.importSFVInfoFromFile(reader);
		sfvInfo.setSFVFileName(file.getName());
		sfvInfo.setChecksum(checksum.getValue());
		return sfvInfo;
	} finally {
		if (reader != null) {
			reader.close();
		}
	}
}
 
開發者ID:drftpd-ng,項目名稱:drftpd3,代碼行數:18,代碼來源:ZipscriptHandler.java

示例9: uncompress

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
private static void uncompress() {
    FileInputStream fis;
    try {
        fis = new FileInputStream("./dir/demo.zip");
        CheckedInputStream cis = new CheckedInputStream(fis,new Adler32());
        ZipInputStream zis = new ZipInputStream(cis);
        BufferedInputStream bis = new BufferedInputStream(zis);
        ZipEntry zipENtry ;
        while ((zipENtry = zis.getNextEntry()) != null){
            System.err.println("read file--->" + zipENtry);
            int x;
            while ((x = bis.read()) != -1){
                System.err.println(x);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:StrongAndroid,項目名稱:JavaNote,代碼行數:20,代碼來源:ZipCompress.java

示例10: Reader

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
/**
 * Construct the reader
 * @param in The stream to read from.
 * @param logVersion The version of the data coming from the stream.
 */
@SuppressWarnings("deprecation")
public Reader(DataInputStream in, int logVersion) {
  this.logVersion = logVersion;
  if (LayoutVersion.supports(Feature.EDITS_CHESKUM, logVersion)) {
    this.checksum = FSEditLog.getChecksumForRead();
  } else {
    this.checksum = null;
  }

  if (this.checksum != null) {
    this.in = new DataInputStream(
        new CheckedInputStream(in, this.checksum));
  } else {
    this.in = in;
  }
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:22,代碼來源:FSEditLogOp.java

示例11: Reader

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
/**
 * Construct the reader
 * @param in The stream to read from.
 * @param logVersion The version of the data coming from the stream.
 */
@SuppressWarnings("deprecation")
public Reader(DataInputStream in, StreamLimiter limiter,
    int logVersion) {
  this.logVersion = logVersion;
  if (LayoutVersion.supports(Feature.EDITS_CHESKUM, logVersion)) {
    this.checksum = new PureJavaCrc32();
  } else {
    this.checksum = null;
  }

  if (this.checksum != null) {
    this.in = new DataInputStream(
        new CheckedInputStream(in, this.checksum));
  } else {
    this.in = in;
  }
  this.limiter = limiter;
  this.cache = new OpInstanceCache();
  this.maxOpSize = DFSConfigKeys.DFS_NAMENODE_MAX_OP_SIZE_DEFAULT;
}
 
開發者ID:ict-carch,項目名稱:hadoop-plus,代碼行數:26,代碼來源:FSEditLogOp.java

示例12: copyFileToCache

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
public void copyFileToCache(Path inFilePath, Object cache_key) throws IOException {
    int inBufferSize = 32*1024;
    int copyBufferSize = 128*1024;

    try (
            CheckedInputStream is = new CheckedInputStream(new BufferedInputStream(Files.newInputStream(inFilePath),inBufferSize),new CRC32());
            CheckedOutputStream os = new CheckedOutputStream(new EhcacheOutputStream(cache, cache_key),new CRC32())
    )
    {
        System.out.println("============ testCopyFileToCacheWithBuffer ====================");

        long start = System.nanoTime();;
        pipeStreamsWithBuffer(is, os, copyBufferSize);
        long end = System.nanoTime();;

        System.out.println("Execution Time = " + formatD.format((double)(end - start) / 1000000) + " millis");
        System.out.println("============================================");
    }
}
 
開發者ID:lanimall,項目名稱:ehcache-extensions,代碼行數:20,代碼來源:FileCopyCacheApp.java

示例13: copyCacheToFile

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
public void copyCacheToFile(Object cache_key, Path outFilePath) throws IOException {
    int copyBufferSize = 512 * 1024; //copy buffer size

    try (
            CheckedInputStream is = new CheckedInputStream(new EhcacheInputStream(cache, cache_key),new CRC32());
            CheckedOutputStream os = new CheckedOutputStream(new BufferedOutputStream(Files.newOutputStream(outFilePath)), new CRC32())
    )
    {
        System.out.println("============ copyCacheToFileUsingStreamDefaultBuffers ====================");
        long start = System.nanoTime();;
        pipeStreamsWithBuffer(is, os, copyBufferSize);
        long end = System.nanoTime();;

        System.out.println("Execution Time = " + formatD.format((double) (end - start) / 1000000) + " millis");
        System.out.println("============================================");
    }
}
 
開發者ID:lanimall,項目名稱:ehcache-extensions,代碼行數:18,代碼來源:FileCopyCacheApp.java

示例14: copyFileToCache

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
@Before
public void copyFileToCache() throws Exception {
    int inBufferSize = 32 * 1024;
    int copyBufferSize = 128 * 1024;

    try (
            CheckedInputStream is = new CheckedInputStream(new BufferedInputStream(Files.newInputStream(IN_FILE_PATH),inBufferSize),new CRC32());
            CheckedOutputStream os = new CheckedOutputStream(new EhcacheOutputStream(cache, cache_key),new CRC32())
    )
    {
        System.out.println("============ copyFileToCache ====================");

        long start = System.nanoTime();;
        pipeStreamsWithBuffer(is, os, copyBufferSize);
        long end = System.nanoTime();;

        System.out.println("Execution Time = " + formatD.format((double)(end - start) / 1000000) + " millis");
        System.out.println("============================================");

        this.fileCheckSum = is.getChecksum().getValue();
        Assert.assertEquals(is.getChecksum().getValue(), os.getChecksum().getValue());
    }
}
 
開發者ID:lanimall,項目名稱:ehcache-extensions,代碼行數:24,代碼來源:EhcacheInputStreamTest.java

示例15: copyCacheToFileUsingStreamSmallerCopyBuffer

import java.util.zip.CheckedInputStream; //導入依賴的package包/類
@Test
public void copyCacheToFileUsingStreamSmallerCopyBuffer() throws Exception {
    int inBufferSize = 128 * 1024; //ehcache input stream internal buffer
    int outBufferSize = 128 * 1024;
    int copyBufferSize = 64 * 1024; //copy buffer size *smaller* than ehcache input stream internal buffer to make sure it works that way

    try (
            CheckedInputStream is = new CheckedInputStream(new EhcacheInputStream(cache, cache_key, inBufferSize),new CRC32());
            CheckedOutputStream os = new CheckedOutputStream(new BufferedOutputStream(Files.newOutputStream(OUT_FILE_PATH),outBufferSize), new CRC32())
    )
    {
        System.out.println("============ copyCacheToFileUsingStreamSmallerCopyBuffer ====================");
        long start = System.nanoTime();;
        pipeStreamsWithBuffer(is, os, copyBufferSize);
        long end = System.nanoTime();;

        System.out.println("Execution Time = " + formatD.format((double)(end - start) / 1000000) + " millis");
        System.out.println("============================================");

        Assert.assertEquals(fileCheckSum, os.getChecksum().getValue());
        Assert.assertEquals(is.getChecksum().getValue(), fileCheckSum);
        Assert.assertEquals(is.getChecksum().getValue(), os.getChecksum().getValue());
    }
}
 
開發者ID:lanimall,項目名稱:ehcache-extensions,代碼行數:25,代碼來源:EhcacheInputStreamTest.java


注:本文中的java.util.zip.CheckedInputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。