當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。