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


Java CRC32.getValue方法代码示例

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


在下文中一共展示了CRC32.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeCrcOfCentralDir

import java.util.zip.CRC32; //导入方法依赖的package包/类
static long computeCrcOfCentralDir(RandomAccessFile raf, CentralDirectory dir) throws IOException {
    CRC32 crc = new CRC32();
    long stillToRead = dir.size;
    raf.seek(dir.offset);
    byte[] buffer = new byte[16384];
    int length = raf.read(buffer, 0, (int) Math.min(16384, stillToRead));
    while (length != -1) {
        crc.update(buffer, 0, length);
        stillToRead -= (long) length;
        if (stillToRead == 0) {
            break;
        }
        length = raf.read(buffer, 0, (int) Math.min(16384, stillToRead));
    }
    return crc.getValue();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:ZipUtil.java

示例2: CRCCheck

import java.util.zip.CRC32; //导入方法依赖的package包/类
/**
 * Check if the CRC of the snapshot file matches the digest.
 * @param f The snapshot file object
 * @return The table list as a string
 * @throws IOException If CRC does not match
 */
public static String CRCCheck(File f) throws IOException {
    final FileInputStream fis = new FileInputStream(f);
    try {
        final BufferedInputStream bis = new BufferedInputStream(fis);
        ByteBuffer crcBuffer = ByteBuffer.allocate(4);
        if (4 != bis.read(crcBuffer.array())) {
            throw new EOFException("EOF while attempting to read CRC from snapshot digest");
        }
        final int crc = crcBuffer.getInt();
        final InputStreamReader isr = new InputStreamReader(bis, "UTF-8");
        CharArrayWriter caw = new CharArrayWriter();
        while (true) {
            int nextChar = isr.read();
            if (nextChar == -1) {
                throw new EOFException("EOF while reading snapshot digest");
            }
            if (nextChar == '\n') {
                break;
            }
            caw.write(nextChar);
        }
        String tableList = caw.toString();
        byte tableListBytes[] = tableList.getBytes("UTF-8");
        CRC32 tableListCRC = new CRC32();
        tableListCRC.update(tableListBytes);
        tableListCRC.update("\n".getBytes("UTF-8"));
        final int calculatedValue = (int)tableListCRC.getValue();
        if (crc != calculatedValue) {
            throw new IOException("CRC of snapshot digest did not match digest contents");
        }

        return tableList;
    } finally {
        try {
            if (fis != null)
                fis.close();
        } catch (IOException e) {}
    }
}
 
开发者ID:s-store,项目名称:s-store,代码行数:46,代码来源:SnapshotUtil.java

示例3: _getCRC

import java.util.zip.CRC32; //导入方法依赖的package包/类
private static long _getCRC(int type, byte[] data)
{
  CRC32 crc = new CRC32();

  // First add in the type bytes
  crc.update((type >> 24) & 0x000000ff);
  crc.update((type >> 16) & 0x000000ff);
  crc.update((type >> 8) & 0x000000ff);
  crc.update(type & 0x000000ff);

  // Now, add in the data
  if (data != null)
    crc.update(data);

  return crc.getValue();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:17,代码来源:PNGEncoder.java

示例4: calculateChecksum

import java.util.zip.CRC32; //导入方法依赖的package包/类
/** Calcule le checksum CRC32 d'un fichier
 * @param path
 * @param fileName
 * @return le checksum du fichier
 * @throws MigrationException 
 */
private int calculateChecksum(String path, String fileName) throws MigrationException {
	final CRC32 crc32 = new CRC32();
	
    try {
    	 String file=path+fileName;
	     InputStream inputStream = getClass().getResourceAsStream(file);
        Reader reader = new InputStreamReader(inputStream, Charset.forName(flywayConfiguration.getEncoding()));

        String str = FileCopyUtils.copyToString(reader);
        inputStream.close();
        BufferedReader bufferedReader = new BufferedReader(new StringReader(str));
        
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            crc32.update(line.getBytes("UTF-8"));
        }
    } catch (Exception e) {
        throw new MigrationException("Unable to calculate checksum pour "+fileName, e);
    }

    return (int) crc32.getValue();
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:29,代码来源:FlywayCallbackMigration.java

示例5: file

import java.util.zip.CRC32; //导入方法依赖的package包/类
public static long file(File f) throws IOException {
    FileInputStream fi = new FileInputStream(f);
    byte[] buff = new byte[65536];
    CRC32 crc32 = new CRC32();
    while (true) {
        try {
            int len = fi.read(buff);
            if (len == -1) {
                break;
            }
            crc32.update(buff, 0, len);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            fi.close();
        }
    }
    return crc32.getValue();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:Crc32.java

示例6: calculateCRC

import java.util.zip.CRC32; //导入方法依赖的package包/类
private static long calculateCRC(@NonNull final InputStream in) throws IOException {
    final CRC32 crc = new CRC32();
    int last = -1;
    int curr;
    while ((curr = in.read()) != -1) {
        if (curr != '\n' && last == '\r') { //NOI18N
            crc.update('\n');               //NOI18N
        }
        if (curr != '\r') {                 //NOI18N
            crc.update(curr);
        }
        last = curr;
    }
    if (last == '\r') {                     //NOI18N
        crc.update('\n');                   //NOI18N
    }
    return crc.getValue();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:Utilities.java

示例7: getCrc

import java.util.zip.CRC32; //导入方法依赖的package包/类
private long getCrc(ZipFile file, ZipEntry entry) throws IOException {
  long crc = -1;
  if (entry != null) {
    crc = entry.getCrc();
    if (crc < 0) {
      CRC32 checksum = new CRC32();

      final InputStream in = file.getInputStream(entry);
      try {
        final byte[] buffer = new byte[1024];
        int count;
        while ((count = in.read(buffer)) >= 0) {
          checksum.update(buffer, 0, count);
        }
        in.close();
        crc = checksum.getValue();
      }
      finally {
        IOUtils.closeQuietly(in);
      }
    }
  }
  return crc;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:25,代码来源:ZipUpdater.java

示例8: getApkFileChecksum

import java.util.zip.CRC32; //导入方法依赖的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

示例9: crc32

import java.util.zip.CRC32; //导入方法依赖的package包/类
public static int crc32(ByteBuffer buf) {
    CRC32 checksum = new CRC32();
    while (buf.hasRemaining()) {
        checksum.update(buf.get());
    }
    return (int) checksum.getValue();
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:8,代码来源:Checksum.java

示例10: setSeed

import java.util.zip.CRC32; //导入方法依赖的package包/类
public void setSeed(long seeds) {
    CRC32 crc32 = new CRC32();
    ByteBuffer buffer = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN);
    buffer.putInt((int) seeds);
    crc32.update(buffer.array());
    this.seed = crc32.getValue();
}
 
开发者ID:CloudLandGame,项目名称:CloudLand-Server,代码行数:8,代码来源:NukkitRandom.java

示例11: deflate

import java.util.zip.CRC32; //导入方法依赖的package包/类
public static DeflateResult deflate(ByteBuffer input) {
    byte[] inputBuf;
    int inputOffset;
    int inputLength = input.remaining();
    if (input.hasArray()) {
        inputBuf = input.array();
        inputOffset = input.arrayOffset() + input.position();
        input.position(input.limit());
    } else {
        inputBuf = new byte[inputLength];
        inputOffset = 0;
        input.get(inputBuf);
    }
    CRC32 crc32 = new CRC32();
    crc32.update(inputBuf, inputOffset, inputLength);
    long crc32Value = crc32.getValue();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Deflater deflater = new Deflater(9, true);
    deflater.setInput(inputBuf, inputOffset, inputLength);
    deflater.finish();
    byte[] buf = new byte[65536];
    while (!deflater.finished()) {
        int chunkSize = deflater.deflate(buf);
        out.write(buf, 0, chunkSize);
    }
    return new DeflateResult(inputLength, crc32Value, out.toByteArray());
}
 
开发者ID:nukc,项目名称:ApkMultiChannelPlugin,代码行数:28,代码来源:ZipUtils.java

示例12: testCRC32Checksum

import java.util.zip.CRC32; //导入方法依赖的package包/类
@Test
public void testCRC32Checksum() throws IOException {
    CRC32 crc32 = new CRC32();
    crc32.update(TEST_DARA.getBytes());
    long expectedCRC32Checksum = crc32.getValue();
    CRC32ChecksumCalculatingInputStream crc32InputStream = new CRC32ChecksumCalculatingInputStream(new ByteArrayInputStream(TEST_DARA.getBytes()));
    while(crc32InputStream.read() != -1);
    assertEquals(expectedCRC32Checksum, crc32InputStream.getCRC32Checksum());
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:10,代码来源:CRC32ChecksumInputStreamTest.java

示例13: getCrc32

import java.util.zip.CRC32; //导入方法依赖的package包/类
public static long getCrc32(final InputStream input) throws IOException {
    CRC32 crc = new CRC32();
    final byte[] buffer = new byte[BUFFER_SIZE];
    int readLength;
    while ((readLength = input.read(buffer)) != -1) {
        crc.update(buffer, 0, readLength);
    }
    return crc.getValue();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:FileUtils.java

示例14: testCrc32Checksum

import java.util.zip.CRC32; //导入方法依赖的package包/类
@Test
public void testCrc32Checksum() throws IOException {
    CRC32 crc32 = new CRC32();
    crc32.update(TEST_DATA.getBytes());
    long expectedCRC32Checksum = crc32.getValue();
    Crc32ChecksumCalculatingInputStream crc32InputStream =
            new Crc32ChecksumCalculatingInputStream(new ByteArrayInputStream(TEST_DATA.getBytes()));
    while (crc32InputStream.read() != -1) {
        ;
    }
    assertEquals(expectedCRC32Checksum, crc32InputStream.getCrc32Checksum());
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:13,代码来源:Crc32ChecksumInputStreamTest.java

示例15: getChecksum

import java.util.zip.CRC32; //导入方法依赖的package包/类
public long getChecksum(ModelDefinition.XMLBindingType bindingType)
{
    final CRC32 crc = new CRC32();

    // construct the crc directly from the model's xml stream
    toXML(bindingType, new OutputStream() {
        public void write(int b) throws IOException
        {
            crc.update(b);
        }
    });

    return crc.getValue();
}
 
开发者ID:Alfresco,项目名称:alfresco-data-model,代码行数:15,代码来源:M2Model.java


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