Example usage for java.util.zip CRC32 getValue

List of usage examples for java.util.zip CRC32 getValue

Introduction

In this page you can find the example usage for java.util.zip CRC32 getValue.

Prototype

@Override
public long getValue() 

Source Link

Document

Returns CRC-32 value.

Usage

From source file:org.broad.igv.util.Utilities.java

/**
 * @param buffer/*from ww  w .j a v a 2 s .com*/
 * @return
 * @throws java.io.IOException
 */
static private long getCrc(byte[] buffer) throws IOException {

    CRC32 crc = new CRC32();

    crc.reset();
    crc.update(buffer, 0, buffer.length);
    return crc.getValue();
}

From source file:com.dcits.govsbu.southernbase.baseproject2.modules.utils.Digests.java

/**
 * crc32php64bitlong//from  www .ja  v  a2 s .  c  om
 */
public static long crc32AsLong(byte[] input) {
    CRC32 crc32 = new CRC32();
    crc32.update(input);
    return crc32.getValue();
}

From source file:com.dcits.govsbu.southernbase.baseproject2.modules.utils.Digests.java

/**
 * crc32.// w w w.  j a  v  a  2 s  .  c  o  m
 */
public static int crc32(byte[] input) {
    CRC32 crc32 = new CRC32();
    crc32.update(input);
    return (int) crc32.getValue();
}

From source file:org.trellisldp.file.FileUtils.java

/**
 * Get a directory for a given resource identifier.
 * @param baseDirectory the base directory
 * @param identifier a resource identifier
 * @return a directory/*from  w ww  .j a v  a2s .c o  m*/
 */
public static File getResourceDirectory(final File baseDirectory, final IRI identifier) {
    requireNonNull(baseDirectory, "The baseDirectory may not be null!");
    requireNonNull(identifier, "The identifier may not be null!");
    final String id = identifier.getIRIString();
    final StringJoiner joiner = new StringJoiner(separator);
    final CRC32 hasher = new CRC32();
    hasher.update(id.getBytes(UTF_8));
    final String intermediate = Long.toHexString(hasher.getValue());

    range(0, intermediate.length() / LENGTH).limit(MAX)
            .forEach(i -> joiner.add(intermediate.substring(i * LENGTH, (i + 1) * LENGTH)));

    joiner.add(md5Hex(id));
    return new File(baseDirectory, joiner.toString());
}

From source file:com.monitor.baseservice.utils.XCodeUtil.java

public static byte[] crcUnsigned(byte[] str, byte[] sign) {
    CRC32 crc = new CRC32();
    crc.update(str);/*from w  w w  .  j a va  2  s  .  c  o m*/
    crc.update(sign);

    long value = crc.getValue();
    if (value < 0) {
        value = 0xFFFFFFFF & value;
    }
    return longToByteArray(value);
}

From source file:com.dcits.govsbu.southernbase.baseproject2.modules.utils.Digests.java

/**
 * crc32php64bitlong//from   w ww  .jav a2  s .  co m
 */
public static long crc32AsLong(String input, Charset charset) {
    CRC32 crc32 = new CRC32();
    crc32.update(input.getBytes(charset));
    return crc32.getValue();
}

From source file:org.apache.pluto.util.assemble.io.JarStreamingAssembly.java

/**
 * Reads the source JarInputStream, copying entries to the destination JarOutputStream. 
 * The web.xml and portlet.xml are cached, and after the entire archive is copied 
 * (minus the web.xml) a re-written web.xml is generated and written to the 
 * destination JAR./*from  w w w.j  a v  a 2  s.com*/
 * 
 * @param source the WAR source input stream
 * @param dest the WAR destination output stream
 * @param dispatchServletClass the name of the dispatch class
 * @throws IOException
 */
public static void assembleStream(JarInputStream source, JarOutputStream dest, String dispatchServletClass)
        throws IOException {

    try {
        //Need to buffer the web.xml and portlet.xml files for the rewritting
        JarEntry servletXmlEntry = null;
        byte[] servletXmlBuffer = null;
        byte[] portletXmlBuffer = null;

        JarEntry originalJarEntry;

        //Read the source archive entry by entry
        while ((originalJarEntry = source.getNextJarEntry()) != null) {

            final JarEntry newJarEntry = smartClone(originalJarEntry);
            originalJarEntry = null;

            //Capture the web.xml JarEntry and contents as a byte[], don't write it out now or
            //update the CRC or length of the destEntry.
            if (Assembler.SERVLET_XML.equals(newJarEntry.getName())) {
                servletXmlEntry = newJarEntry;
                servletXmlBuffer = IOUtils.toByteArray(source);
            }

            //Capture the portlet.xml contents as a byte[]
            else if (Assembler.PORTLET_XML.equals(newJarEntry.getName())) {
                portletXmlBuffer = IOUtils.toByteArray(source);
                dest.putNextEntry(newJarEntry);
                IOUtils.write(portletXmlBuffer, dest);
            }

            //Copy all other entries directly to the output archive
            else {
                dest.putNextEntry(newJarEntry);
                IOUtils.copy(source, dest);
            }

            dest.closeEntry();
            dest.flush();

        }

        // If no portlet.xml was found in the archive, skip the assembly step.
        if (portletXmlBuffer != null) {
            // container for assembled web.xml bytes
            final byte[] webXmlBytes;

            // Checks to make sure the web.xml was found in the archive
            if (servletXmlBuffer == null) {
                throw new FileNotFoundException(
                        "File '" + Assembler.SERVLET_XML + "' could not be found in the source input stream.");
            }

            //Create streams of the byte[] data for the updater method
            final InputStream webXmlIn = new ByteArrayInputStream(servletXmlBuffer);
            final InputStream portletXmlIn = new ByteArrayInputStream(portletXmlBuffer);
            final ByteArrayOutputStream webXmlOut = new ByteArrayOutputStream(servletXmlBuffer.length);

            //Update the web.xml
            WebXmlStreamingAssembly.assembleStream(webXmlIn, portletXmlIn, webXmlOut, dispatchServletClass);
            IOUtils.copy(webXmlIn, webXmlOut);
            webXmlBytes = webXmlOut.toByteArray();

            //If no compression is being used (STORED) we have to manually update the size and crc
            if (servletXmlEntry.getMethod() == ZipEntry.STORED) {
                servletXmlEntry.setSize(webXmlBytes.length);
                final CRC32 webXmlCrc = new CRC32();
                webXmlCrc.update(webXmlBytes);
                servletXmlEntry.setCrc(webXmlCrc.getValue());
            }

            //write out the assembled web.xml entry and contents
            dest.putNextEntry(servletXmlEntry);
            IOUtils.write(webXmlBytes, dest);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Jar stream " + source + " successfully assembled.");
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No portlet XML file was found, assembly was not required.");
            }

            //copy the original, unmodified web.xml entry to the destination
            dest.putNextEntry(servletXmlEntry);
            IOUtils.write(servletXmlBuffer, dest);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Jar stream " + source + " successfully assembled.");
            }
        }

    } finally {

        dest.flush();
        dest.close();

    }
}

From source file:com.dcits.govsbu.southernbase.baseproject2.modules.utils.Digests.java

/**
 * crc32./*  ww w .j  a  v a 2s.  c  o m*/
 */
public static int crc32(String input, Charset charset) {
    CRC32 crc32 = new CRC32();
    crc32.update(input.getBytes(charset));
    return (int) crc32.getValue();
}

From source file:com.dcits.govsbu.southernbase.baseproject2.modules.utils.Digests.java

/**
 * crc32php64bitlong//from w  w  w  . j  av a  2s . co  m
 */
public static long crc32AsLong(String input) {
    CRC32 crc32 = new CRC32();
    crc32.update(input.getBytes(Charsets.UTF8));
    return crc32.getValue();
}

From source file:com.dcits.govsbu.southernbase.baseproject2.modules.utils.Digests.java

/**
 * crc32.//from  w  w  w  . ja  va 2  s .  co m
 */
public static int crc32(String input) {
    CRC32 crc32 = new CRC32();
    crc32.update(input.getBytes(Charsets.UTF8));
    return (int) crc32.getValue();
}