本文整理汇总了Java中java.util.zip.CheckedInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java CheckedInputStream.read方法的具体用法?Java CheckedInputStream.read怎么用?Java CheckedInputStream.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.CheckedInputStream
的用法示例。
在下文中一共展示了CheckedInputStream.read方法的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;
}
}
示例2: 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;
}
}
示例3: 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;
}
示例4: 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();
}
示例5: 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();
}
示例6: 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;
}
示例7: 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;
}
示例8: crc32
import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
public static long crc32(File testFile) throws FileNotFoundException, IOException
{
CheckedInputStream inputStream = new CheckedInputStream(new FileInputStream(testFile), new CRC32());
try
{
// Read 4k at a time and discard the incoming data
byte[] buffer = new byte[4096];
while (inputStream.read(buffer) >= 0)
{
// Ignore input
}
return inputStream.getChecksum().getValue();
}
finally
{
IOUtils.closeQuietly(inputStream);
}
}
示例9: 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");
}
}
示例10: 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;
}
示例11: getChecksum
import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
public static long getChecksum(String test) {
try {
byte buffer[] = test.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
CheckedInputStream cis = new CheckedInputStream(bais, new Adler32());
byte readBuffer[] = new byte[buffer.length];
cis.read(readBuffer);
return cis.getChecksum().getValue();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例12: getCheckSum
import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
/**
* Método getCheckSum
*
* @param pFile
* @return long
*/
private static long getCheckSum(File pFile) {
long l = 0;
try {
CheckedInputStream vCIS = new CheckedInputStream(new FileInputStream(pFile), new Adler32());
byte[] arrby = new byte[128];
while (vCIS.read(arrby) >= 0) {
}
l = vCIS.getChecksum().getValue();
} catch (IOException e) {
// empty catch block
}
return l;
}
示例13: getExpectedChecksum
import java.util.zip.CheckedInputStream; //导入方法依赖的package包/类
private ChecksumValue getExpectedChecksum(File file)
throws Exception
{
CheckedInputStream cis = new CheckedInputStream(new FileInputStream(file), new Adler32());
byte [] buf = new byte[defaultBufferSize];
while(cis.read(buf) >= 0)
{
// must read entire file to update the checksum
}
return new ChecksumValue(cis.getChecksum());
}
示例14: 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);
}
示例15: 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);
}