Search in sources :

Example 31 with Checksum

use of java.util.zip.Checksum in project lucene-solr by apache.

the class ReplicationHandler method getConfFileInfoFromCache.

/**
   * For configuration files, checksum of the file is included because, unlike index files, they may have same content
   * but different timestamps.
   * <p/>
   * The local conf files information is cached so that everytime it does not have to compute the checksum. The cache is
   * refreshed only if the lastModified of the file changes
   */
List<Map<String, Object>> getConfFileInfoFromCache(NamedList<String> nameAndAlias, final Map<String, FileInfo> confFileInfoCache) {
    List<Map<String, Object>> confFiles = new ArrayList<>();
    synchronized (confFileInfoCache) {
        File confDir = new File(core.getResourceLoader().getConfigDir());
        Checksum checksum = null;
        for (int i = 0; i < nameAndAlias.size(); i++) {
            String cf = nameAndAlias.getName(i);
            File f = new File(confDir, cf);
            //must not happen
            if (!f.exists() || f.isDirectory())
                continue;
            FileInfo info = confFileInfoCache.get(cf);
            if (info == null || info.lastmodified != f.lastModified() || info.size != f.length()) {
                if (checksum == null)
                    checksum = new Adler32();
                info = new FileInfo(f.lastModified(), cf, f.length(), getCheckSum(checksum, f));
                confFileInfoCache.put(cf, info);
            }
            Map<String, Object> m = info.getAsMap();
            if (nameAndAlias.getVal(i) != null)
                m.put(ALIAS, nameAndAlias.getVal(i));
            confFiles.add(m);
        }
    }
    return confFiles;
}
Also used : Checksum(java.util.zip.Checksum) ArrayList(java.util.ArrayList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) HashMap(java.util.HashMap) MetricsMap(org.apache.solr.metrics.MetricsMap) File(java.io.File) Adler32(java.util.zip.Adler32)

Example 32 with Checksum

use of java.util.zip.Checksum in project lucene-solr by apache.

the class TestBufferedChecksum method testSimple.

public void testSimple() {
    Checksum c = new BufferedChecksum(new CRC32());
    c.update(1);
    c.update(2);
    c.update(3);
    assertEquals(1438416925L, c.getValue());
}
Also used : CRC32(java.util.zip.CRC32) Checksum(java.util.zip.Checksum)

Example 33 with Checksum

use of java.util.zip.Checksum in project poi by apache.

the class IOUtils method calculateChecksum.

/**
     * Calculate checksum on all the data read from input stream.
     *
     * This should be more efficient than the equivalent code
     * {@code IOUtils.calculateChecksum(IOUtils.toByteArray(stream))}
     */
public static long calculateChecksum(InputStream stream) throws IOException {
    Checksum sum = new CRC32();
    byte[] buf = new byte[4096];
    int count;
    while ((count = stream.read(buf)) != -1) {
        if (count > 0) {
            sum.update(buf, 0, count);
        }
    }
    return sum.getValue();
}
Also used : CRC32(java.util.zip.CRC32) Checksum(java.util.zip.Checksum)

Example 34 with Checksum

use of java.util.zip.Checksum in project iris by chicc999.

the class Message method getBodyCRC.

public long getBodyCRC() {
    if (bodyCRC == 0) {
        if (body != null && body.length > 0) {
            Checksum checksum = new Adler32();
            checksum.update(body, 0, body.length);
            bodyCRC = checksum.getValue();
        }
    }
    return bodyCRC;
}
Also used : Checksum(java.util.zip.Checksum) Adler32(java.util.zip.Adler32)

Example 35 with Checksum

use of java.util.zip.Checksum in project processdash by dtuma.

the class PackageLaunchProfile method calculateContentToken.

private String calculateContentToken() throws IOException {
    List<File> files = new ArrayList<File>();
    for (FileSet fs : filesets) {
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        for (String name : ds.getIncludedFiles()) files.add(new File(ds.getBasedir(), name));
    }
    if (files.isEmpty())
        throw new BuildException("You must designate at least one file " + "to include in the launch profile.");
    Collections.sort(files, FILENAME_SORTER);
    Checksum ck = new Adler32();
    for (File f : files) calcChecksum(f, ck);
    return Long.toString(Math.abs(ck.getValue()), Character.MAX_RADIX);
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) Checksum(java.util.zip.Checksum) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Adler32(java.util.zip.Adler32)

Aggregations

Checksum (java.util.zip.Checksum)35 CRC32 (java.util.zip.CRC32)14 IOException (java.io.IOException)10 Adler32 (java.util.zip.Adler32)9 File (java.io.File)6 EOFException (java.io.EOFException)3 FileInputStream (java.io.FileInputStream)3 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 BufferedOutputStream (java.io.BufferedOutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileOutputStream (java.io.FileOutputStream)2 RandomAccessFile (java.io.RandomAccessFile)2 Date (java.util.Date)2 DataChecksum (org.apache.hadoop.util.DataChecksum)2 PureJavaCrc32 (org.apache.hadoop.util.PureJavaCrc32)2 BinaryInputArchive (org.apache.jute.BinaryInputArchive)2 Record (org.apache.jute.Record)2 FileHeader (org.apache.zookeeper_voltpatches.server.persistence.FileHeader)2 ByteBuf (io.netty.buffer.ByteBuf)1