List of usage examples for java.util.zip CRC32 update
@Override public void update(ByteBuffer buffer)
From source file:com.monitor.baseservice.utils.XCodeUtil.java
public static byte[] crcUnsigned(byte[] str, byte[] sign) { CRC32 crc = new CRC32(); crc.update(str); crc.update(sign);/*from ww w . jav a2 s. c o m*/ long value = crc.getValue(); if (value < 0) { value = 0xFFFFFFFF & value; } return longToByteArray(value); }
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./*w w w. j a va 2 s. co m*/ * * @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.// w w w . j a v a2 s . c om */ public static int crc32(byte[] input) { CRC32 crc32 = new CRC32(); crc32.update(input); return (int) crc32.getValue(); }
From source file:com.dcits.govsbu.southernbase.baseproject2.modules.utils.Digests.java
/** * crc32./*from w ww . j a v a 2s . c om*/ */ public static int crc32(String input) { CRC32 crc32 = new CRC32(); crc32.update(input.getBytes(Charsets.UTF8)); return (int) crc32.getValue(); }
From source file:com.dcits.govsbu.southernbase.baseproject2.modules.utils.Digests.java
/** * crc32.//from w w w. j av a 2 s .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 ww w. j av a 2s . co m */ 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
/** * crc32php64bitlong/*w w w. ja v a 2s. c o 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
/** * crc32php64bitlong//from www . j av a 2s.c om */ public static long crc32AsLong(String input, Charset charset) { CRC32 crc32 = new CRC32(); crc32.update(input.getBytes(charset)); return crc32.getValue(); }
From source file:com.rom.jmultipatcher.Utils.java
public static long getCRC32(final String filepath, final int bytesBeforeEnd) throws IOException { final CRC32 sum_control = new CRC32(); final byte[] fileAsByteArray = FileUtils.readFileToByteArray(new File(filepath)); final byte[] copyOfRange = Arrays.copyOfRange(fileAsByteArray, 0, fileAsByteArray.length - bytesBeforeEnd); sum_control.update(copyOfRange); return sum_control.getValue(); }
From source file:com.aimluck.eip.util.ALCellularUtils.java
/** * ?? ID ??? URL ??????/* w w w .ja va2 s . com*/ * * @param username * @return */ public static String getCheckValueForCellLogin(String username, String userid) { if (username == null || username.length() == 0 || userid == null) { return ""; } String marge = username + userid; CRC32 crc32 = new CRC32(); crc32.update(marge.getBytes()); long value = crc32.getValue(); String base64value = null; try { base64value = new String(Base64.encodeBase64(String.valueOf(value).getBytes())); } catch (Exception e) { } return (base64value == null) ? "" : base64value.toLowerCase(); }