当前位置: 首页>>代码示例>>Java>>正文


Java CheckedInputStream.close方法代码示例

本文整理汇总了Java中java.util.zip.CheckedInputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java CheckedInputStream.close方法的具体用法?Java CheckedInputStream.close怎么用?Java CheckedInputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.zip.CheckedInputStream的用法示例。


在下文中一共展示了CheckedInputStream.close方法的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: 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

示例5: getCRC32

import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
/**
 * Find the Zip CRC32 checksum in the desired base.
 * Mediaflux uses this algorithm with base 16  for setting its content checksum
 * This algorithm copes with large files
 * 
 * @param f
 * @param radix
 * @return
 * @throws Throwable
 */
public static String getCRC32 (File f, int radix) throws Throwable {


	FileInputStream file = new FileInputStream(f);
	CheckedInputStream check = 
			new CheckedInputStream(file, new CRC32());
	BufferedInputStream in = 
			new BufferedInputStream(check);
	while (in.read() != -1) {
		// Read file in completely
	}
	in.close();
	long n = check.getChecksum().getValue();
	check.close();
	return Long.toString(n, radix);

}
 
开发者ID:uom-daris,项目名称:daris,代码行数:28,代码来源:ZipUtil.java

示例6: test_read

import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
public void test_read() throws Exception {
    // testing that the return by skip is valid
    InputStream checkInput = Support_Resources
            .getStream("hyts_checkInput.txt");
    CheckedInputStream checkIn = new CheckedInputStream(checkInput,
            new CRC32());
    checkIn.read();
    checkIn.close();
    try {
        checkIn.read();
        fail("IOException expected.");
    } catch (IOException ee) {
        // expected
    }
    checkInput.close();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:17,代码来源:CheckedInputStreamTest.java

示例7: CheckedInputStream

import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
public void test_read$byteII() throws Exception {
    // testing that the return by skip is valid
    InputStream checkInput = Support_Resources
            .getStream("hyts_checkInput.txt");
    CheckedInputStream checkIn = new CheckedInputStream(checkInput,
            new CRC32());
    byte buff[] = new byte[50];
    checkIn.read(buff, 10, 5);
    checkIn.close();
    try {
        checkIn.read(buff, 10, 5);
        fail("IOException expected.");
    } catch (IOException ee) {
        // expected
    }
    checkInput.close();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:18,代码来源:CheckedInputStreamTest.java

示例8: getCRC

import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
private Long getCRC(URL zipUrl) {
    Long result = -1l;
    try {
        CRC32 crc = new CRC32();
        CheckedInputStream cis = new CheckedInputStream(zipUrl.openStream(), crc);

        byte[] buffer = new byte[1024];
        int length;

        //read the entry from zip file and extract it to disk
        while( (length = cis.read(buffer)) > 0);

        cis.close();

        result = crc.getValue();
    } catch (IOException e) {
        LOG.warn("Unable to calculate CRC, resource doesn't exist?", e);
    }
    return result;
}
 
开发者ID:kuali,项目名称:rice,代码行数:21,代码来源:URLMonitor.java

示例9: checksumJar

import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
public static Checksum checksumJar(JarFile file) throws IOException {
  Checksum checksum = new Checksum(file.toString());
  Enumeration entries = file.entries();
  while (entries.hasMoreElements()) {
    JarEntry entry = (JarEntry) entries.nextElement();
    if (!entry.isDirectory()) {
      CheckedInputStream fin = new CheckedInputStream(new BufferedInputStream(file.getInputStream(entry)),
          new Adler32());
      byte buffer[] = new byte[8192];
      while ((fin.read(buffer)) != -1) {
        /* ignore ... */
      }
      Long checkSum = new Long(fin.getChecksum().getValue());
      checksum.add(entry.toString(), checkSum);
      fin.close();
    }
  }
  return checksum;
}
 
开发者ID:thinkberg,项目名称:snipsnap,代码行数:20,代码来源:JarUtil.java

示例10: writeFolderToZip

import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
private void writeFolderToZip(File folder, ZipOutputStream zip, String baseName, String repoName)
		throws IOException {
	File[] files = folder.listFiles();
	CRC32 crc = new CRC32();
	for (File file : files) {
		if (file.isDirectory()) {
			writeFolderToZip(file, zip, baseName, repoName);
		} else {
			String name = repoName + file.getAbsolutePath().substring(baseName.length());
			LOG.debug("Name {} derived vrom {}", name, baseName);
			ZipEntry entry = new ZipEntry(name);
			zip.putNextEntry(entry);
			crc.reset();
			CheckedInputStream in = new CheckedInputStream(new FileInputStream(file), crc);
			ByteStreams.copy(in, zip);
			in.close();
			entry.setCrc(in.getChecksum().getValue());
			zip.closeEntry();
		}
	}
}
 
开发者ID:devhub-tud,项目名称:devhub-prototype,代码行数:22,代码来源:RepositoryDownloader.java

示例11: getPartChecksum

import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
/**
 * Return the CRC checksum of a given part
 *
 * @param partIndex
 *            the index of the part
 * @param isAttachment
 *            true if the part is an attachment
 * @return the part checksum
 * @throws PackageException
 */
@PublicAtsApi
public long getPartChecksum(
                             int partIndex,
                             boolean isAttachment ) throws PackageException {

    InputStream partDataStream = getPartData(partIndex, isAttachment);

    if (partDataStream != null) {
        try {
            SeekInputStream seekDataStream = new SeekInputStream(partDataStream);
            seekDataStream.seek(0);

            // create a new crc and reset it
            CRC32 crc = new CRC32();

            // use checked stream to get the checksum
            CheckedInputStream stream = new CheckedInputStream(seekDataStream, crc);

            int bufLen = 4096;
            byte[] buffer = new byte[bufLen];
            int numBytesRead = bufLen;

            while (numBytesRead == bufLen) {
                numBytesRead = stream.read(buffer, 0, bufLen);
            }

            long checksum = stream.getChecksum().getValue();
            stream.close();

            return checksum;
        } catch (IOException ioe) {
            throw new PackageException(ioe);
        }
    } else {
        throw new MimePartWithoutContentException("MIME part does not have any content");
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:48,代码来源:MimePackage.java

示例12: calculateCRC32

import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
/**
 * Calculates the CRC32 value of a file.
 * 
 * @param file File to compute the CRC value
 * @return CRC value formatted in 8 length hexadecimal in lowercase
 */
public static String calculateCRC32(File file) throws ChecksumException
{
    if(file == null)
    {
        return null;
    }
    String hex = "";
    try
    {
        CheckedInputStream cis = new CheckedInputStream(new FileInputStream(file), new CRC32());
        byte[] buf = new byte[10240]; // 10mb

        while(cis.read(buf) >= 0)
            ;

        hex = Long.toHexString(cis.getChecksum().getValue());
        cis.close();
    }
    catch (IOException | NullPointerException e)
    {
        throw new ChecksumException("Unable to determine CRC32 value for file: " + file.getName());  
    }
    for(int i = hex.length(); i < CRC32_LENGTH; i++)
    {
        hex = "0" + hex;
    }
    return hex;
}
 
开发者ID:tonyhsu17,项目名称:Synchive,代码行数:35,代码来源:Utilities.java

示例13: getCRC32

import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
static String getCRC32(InputStream in) throws Throwable {
    CheckedInputStream cin = new CheckedInputStream(
            new BufferedInputStream(in), new CRC32());
    byte[] buffer = new byte[1024];
    try {
        while (cin.read(buffer) != -1) {
            // Read file in completely
        }
    } finally {
        cin.close();
        in.close();
    }
    long value = cin.getChecksum().getValue();
    return Long.toHexString(value);
}
 
开发者ID:uom-daris,项目名称:daris,代码行数:16,代码来源:SvcAssetContentChecksumGenerate.java

示例14: getCRC32

import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
public static String getCRC32(InputStream in) throws Throwable {
    CheckedInputStream cin = new CheckedInputStream(new BufferedInputStream(in), new CRC32());
    byte[] buffer = new byte[1024];
    try {
        while (cin.read(buffer) != -1) {
            // Read file in completely
        }
    } finally {
        cin.close();
        in.close();
    }
    long value = cin.getChecksum().getValue();
    return Long.toHexString(value);
}
 
开发者ID:uom-daris,项目名称:daris,代码行数:15,代码来源:ChecksumUtils.java

示例15: createTestFile

import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
static void createTestFile() throws Throwable {

		/**
		 * Generate a temporary file for uploading/downloading
		 */
		sourceFile = new File(System.getProperty("user.home"), "sftp-file");
		java.util.Random rnd = new java.util.Random();

		FileOutputStream out = new FileOutputStream(sourceFile);
		byte[] buf = new byte[1024000];
		for (int i = 0; i < 100; i++) {
			rnd.nextBytes(buf);
			out.write(buf);
		}
		out.close();

		CheckedInputStream cis = new CheckedInputStream(new FileInputStream(
				sourceFile), new Adler32());

		try {
			byte[] tempBuf = new byte[16384];
			while (cis.read(tempBuf) >= 0) {
			}
			sourceFileChecksum = cis.getChecksum().getValue();
		} catch (IOException e) {
		} finally {
			cis.close();
		}
	}
 
开发者ID:sshtools,项目名称:j2ssh-maverick,代码行数:30,代码来源:PerformanceTest.java


注:本文中的java.util.zip.CheckedInputStream.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。