org.apache.commons.io.FileUtils.checksumCRC32()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(307)

本文整理了Java中org.apache.commons.io.FileUtils.checksumCRC32()方法的一些代码示例,展示了FileUtils.checksumCRC32()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.checksumCRC32()方法的具体详情如下:
包路径:org.apache.commons.io.FileUtils
类名称:FileUtils
方法名:checksumCRC32

FileUtils.checksumCRC32介绍

[英]Computes the checksum of a file using the CRC32 checksum routine. The value of the checksum is returned.
[中]使用CRC32校验和例程计算文件的校验和。返回校验和的值。

代码示例

代码示例来源:origin: alibaba/jvm-sandbox

private ModuleClassLoader(final File moduleJarFile,
             final File tempModuleJarFile,
             final ClassLoader sandboxClassLoader) throws IOException {
  super(
      new URL[]{new URL("file:" + tempModuleJarFile.getPath())},
      new Routing(
          sandboxClassLoader,
          "^com\\.alibaba\\.jvm\\.sandbox\\.api\\..*",
          "^javax\\.servlet\\..*",
          "^javax\\.annotation\\.Resource.*$"
      )
  );
  this.checksumCRC32 = FileUtils.checksumCRC32(moduleJarFile);
  this.moduleJarFile = moduleJarFile;
  this.tempModuleJarFile = tempModuleJarFile;
  try {
    cleanProtectionDomainWhichCameFromModuleClassLoader();
    logger.debug("clean ProtectionDomain in {}'s acc success.", this);
  } catch (Throwable e) {
    logger.warn("clean ProtectionDomain in {}'s acc failed.", this, e);
  }
}

代码示例来源:origin: commons-io/commons-io

@Test
public void testChecksumCRC32() throws Exception {
  // create a test file
  final String text = "Imagination is more important than knowledge - Einstein";
  final File file = new File(getTestDirectory(), "checksum-test.txt");
  FileUtils.writeStringToFile(file, text, "US-ASCII");
  // compute the expected checksum
  final Checksum expectedChecksum = new CRC32();
  expectedChecksum.update(text.getBytes("US-ASCII"), 0, text.length());
  final long expectedValue = expectedChecksum.getValue();
  // compute the checksum of the file
  final long resultValue = FileUtils.checksumCRC32(file);
  assertEquals(expectedValue, resultValue);
}

代码示例来源:origin: alibaba/jvm-sandbox

final long checksumCRC32;
try {
  checksumCRC32 = FileUtils.checksumCRC32(jarFile);
} catch (IOException cause) {
  logger.warn("soft-flushing module: compute module-jar CRC32 occur error. module-jar={};", jarFile, cause);

代码示例来源:origin: gncloud/fastcatsearch

public void doChecksumValidation() throws IOException{
  //checksumCRC32
  long actualChecksum = FileUtils.checksumCRC32(file);
  if(actualChecksum != checksumCRC32){
    throw new IOException("파일의 checksum이 일치하지 않습니다.expected="+checksumCRC32+", actual="+actualChecksum+", file="+filePath);
  }else{
    logger.debug("파일검증완료. checksum={}, file={}", checksumCRC32, filePath);
  }
  
}

代码示例来源:origin: querydsl/apt-maven-plugin

private static void copyIfChanged(File source, File target) throws IOException {
  if (target.exists()) {
    if (source.length() == target.length() && FileUtils.checksumCRC32(source) == FileUtils.checksumCRC32(target)) {
      return;
    } else {
      target.delete();
    }
  }
  if (!source.renameTo(target)) {
    Files.move(source, target);
  }
}

代码示例来源:origin: org.xworker/xworker_core

public static long checksumCRC32(ActionContext actionContext) throws IOException{
  Thing self = (Thing) actionContext.get("self");
  Object file = self.doAction("getFile", actionContext);
  if(file == null){
    return 0;
  }else if(file instanceof File){
    return FileUtils.checksumCRC32((File) file);
  }else {
    String fileName = String.valueOf(file);
    return FileUtils.checksumCRC32(new File(fileName));
  }
}

代码示例来源:origin: ata4/bspsrc

public long getFileCRC() throws IOException {
    return FileUtils.checksumCRC32(bspFile.getFile().toFile());
  }
}

代码示例来源:origin: org.codehaus.izpack/izpack-test-common

/**
   * Verifies that two files have the same content.
   * <p/>
   * The files must have different paths.
   *
   * @param expected the expected file
   * @param actual   the actual file
   */
  public static void assertFileEquals(File expected, File actual)
  {
    assertTrue("File not found", actual.exists());
    assertFalse("Path differs", actual.getAbsolutePath().equals(expected.getAbsolutePath()));
    assertEquals("File length differs", expected.length(), actual.length());
    try
    {
      assertEquals("Checksum differs", FileUtils.checksumCRC32(expected), FileUtils.checksumCRC32(actual));
    }
    catch (IOException exception)
    {
      fail(exception.getMessage());
    }
  }
}

代码示例来源:origin: cereda/arara

/**
 * Calculates the CRC32 checksum of the provided file.
 * @param file The file.
 * @return A string containing the CRC32 checksum of the provided file.
 * @throws AraraException Something wrong happened, to be caught in the
 * higher levels.
 */
public static String calculateHash(File file) throws AraraException {
  try {
    long result = FileUtils.checksumCRC32(file);
    return String.format("%08x", result);
  } catch (IOException exception) {
    throw new AraraException(
        messages.getMessage(
            Messages.ERROR_CALCULATEHASH_IO_EXCEPTION
        ),
        exception
    );
  }
}

代码示例来源:origin: com.github.macgregor/alexandria-core

/**
 * Determine the state of a document when processing the sync phase.
 *
 * {@link #sourcePath} should be made absolute before calling this or you risk the checksum failing.
 *
 * @see Context#makePathsAbsolute()
 *
 * @return  state that can be used to determine how to process the document
 * @throws IOException  when problems working with {@link #sourcePath} occur.
 */
public State determineState() throws IOException {
  if(this.deletedOn().isPresent()){
    return State.DELETED;
  }
  if(!sourcePath.toFile().exists()){
    return State.DELETE;
  }
  if (!this.remoteUri().isPresent()) {
    return State.CREATE;
  }
  long currentChecksum = FileUtils.checksumCRC32(sourcePath.toFile());
  if(this.sourceChecksum().isPresent() && this.sourceChecksum().get().equals(currentChecksum)){
    return State.CURRENT;
  }
  this.convertedChecksum(Optional.empty());
  return State.UPDATE;
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

private static ArchiveEntry newArchive(File file) throws IOException {
  ZipArchiveEntry zipEntry = new ZipArchiveEntry(file.getName());
  zipEntry.setSize(file.length());
  zipEntry.setCompressedSize(zipEntry.getSize());
  zipEntry.setCrc(FileUtils.checksumCRC32(file));
  return zipEntry;
}

代码示例来源:origin: org.jumpmind.symmetric/symmetric-core

this.crc32Checksum = FileUtils.checksumCRC32(file);
} catch (FileNotFoundException ex) {
  this.lastEventType = LastEventType.DELETE;

代码示例来源:origin: org.xworker/xworker_core

if(FileUtils.checksumCRC32(source) != FileUtils.checksumCRC32(target)){
  if(source.lastModified() < target.lastModified()){
    if("keepSourceSame".equals(type) || "keepSame".equals(type)){

代码示例来源:origin: com.github.macgregor/alexandria-core

long currentChecksum = FileUtils.checksumCRC32(convertedPathGuess.toFile());
if(metadata.convertedChecksum().isPresent() && metadata.convertedChecksum().get().equals(currentChecksum)){
  context.convertedPath(metadata, convertedPathGuess);

代码示例来源:origin: org.ikasan/ikasan-utility-endpoint

long checksum = FileUtils.checksumCRC32(file);
File checksumFile = new File(configuration.getFilename() + ".cr32");
FileUtils.writeStringToFile(checksumFile, String.valueOf(checksum), configuration.getEncoding());

代码示例来源:origin: com.github.macgregor/alexandria-core

convertAsNeeded(context, metadata);
remote.create(context, metadata);
currentChecksum = FileUtils.checksumCRC32(metadata.sourcePath().toFile());
metadata.sourceChecksum(Optional.of(currentChecksum));
log.info(String.format("%s (remote: %s) created on remote", metadata.sourceFileName(), metadata.remoteUri().orElse(null)));
convertAsNeeded(context, metadata);
remote.update(context, metadata);
currentChecksum = FileUtils.checksumCRC32(metadata.sourcePath().toFile());
metadata.sourceChecksum(Optional.of(currentChecksum));
log.info(String.format("%s (remote: %s) updated on remote.", metadata.sourceFileName(), metadata.remoteUri().orElse(null)));

代码示例来源:origin: com.github.macgregor/alexandria-core

/**
   * Convert the document from markdown to html.
   *
   * @see Markdown
   *
   * @param context  Alexandria context containing information necessary to calculate the path
   * @param metadata  the particular document being processed
   * @throws AlexandriaException  wrapper for any IOException thrown during conversion to make it integrate with {@link BatchProcess}
   */
  protected static void convert(Context context, Config.DocumentMetadata metadata) throws AlexandriaException {
    try {
      Path convertedPath = convertedPath(context, metadata);
      Path sourcePath = metadata.sourcePath();
      Markdown.toHtml(sourcePath, convertedPath);
      metadata.convertedChecksum(Optional.of(FileUtils.checksumCRC32(convertedPath.toFile())));
      context.convertedPath(metadata, convertedPath);
    } catch (Exception e) {
      throw new AlexandriaException.Builder()
          .withMessage(String.format("Unexcepted error converting %s to html", metadata.sourcePath()))
          .causedBy(e)
          .metadataContext(metadata)
          .build();
    }
  }
}

代码示例来源:origin: gncloud/fastcatsearch

long checksumCRC32 = FileUtils.checksumCRC32(sourcefile);//checksum 생성은 시간이 조금 소요되는 작업. 3G => 10초.
long fileSize = sourcefile.length();
long writeSize = 0;

相关文章

FileUtils类方法