List of usage examples for java.util.zip CRC32 CRC32
public CRC32()
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);/* w w w .jav a 2 s .c o m*/ return sum_control.getValue(); }
From source file:org.openmrs.module.sync.server.ConnectionRequest.java
/** * Public constructor that creates a quest * //w ww.jav a 2 s . c om * @param content * @param useCompression * @throws SyncException */ public ConnectionRequest(String content, boolean useCompression) throws SyncException { try { this.useCompression = useCompression; this.baos = new ByteArrayOutputStream(); this.cos = new CheckedOutputStream(baos, new CRC32()); if (useCompression) { this.zos = new GZIPOutputStream(new BufferedOutputStream(cos)); IOUtils.copy(new ByteArrayInputStream(content.getBytes("UTF-8")), zos); IOUtils.closeQuietly(zos); } else { IOUtils.copy(new ByteArrayInputStream(content.getBytes("UTF-8")), baos); IOUtils.closeQuietly(baos); } this.checksum = cos.getChecksum().getValue(); } catch (IOException e) { throw new SyncException(e); } }
From source file:io.blobkeeper.file.util.FileUtils.java
public static long getCrc(byte[] data) { CRC32 crc = new CRC32(); crc.update(data); return crc.getValue(); }
From source file:com.aimluck.eip.util.ALCellularUtils.java
/** * ?? ID ??? URL ??????//from w w w . j a v a2 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(); }
From source file:io.blobkeeper.file.util.FileUtils.java
public static long getCrc(@NotNull File file) { CRC32 crc = new CRC32(); while (true) { ByteBuffer buffer = ByteBuffer.allocate(CHUNK_SIZE); while (buffer.hasRemaining()) { int bytes = 0; try { bytes = file.getFileChannel().read(buffer); } catch (IOException e) { log.error("Can't read blob file " + file, e); throw new IllegalArgumentException(e); }//from w w w . ja v a 2 s . com if (bytes < 0) { break; } } buffer.flip(); if (buffer.remaining() == 0) { break; } else { crc.update(buffer.array()); } } return crc.getValue(); }
From source file:org.alfresco.repo.domain.node.ChildAssocEntity.java
/** * Find a CRC value for the full QName using UTF-8 conversion. * // w w w . j a v a 2 s . c o m * @param qname the association qname * @return Returns the CRC value (UTF-8 compatible) */ public static Long getQNameCrc(QName qname) { CRC32 crc = new CRC32(); try { crc.update(qname.getNamespaceURI().getBytes("UTF-8")); crc.update(qname.getLocalName().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("UTF-8 encoding is not supported"); } return crc.getValue(); }
From source file:com.nridge.core.base.std.FilUtl.java
/** * Generates a unique path based on the parameters provided. * * @param aPathName Optional path name - if not provided, then the current working directory will be used. * @param aPrefix Path name prefix (appended with random id) * * @return A unique path name./*from w ww .j a v a 2 s .com*/ */ static public String generateUniquePathName(String aPathName, String aPrefix) { if (StringUtils.isEmpty(aPathName)) aPathName = getWorkingDirectory(); if (StringUtils.isEmpty(aPathName)) aPrefix = "subpath"; // http://www.javapractices.com/topic/TopicAction.do?Id=56 UUID uniqueId = UUID.randomUUID(); byte idBytes[] = uniqueId.toString().getBytes(); Checksum checksumValue = new CRC32(); checksumValue.update(idBytes, 0, idBytes.length); long longValue = checksumValue.getValue(); return String.format("%s%c%s_%d", aPathName, File.separatorChar, aPrefix, longValue); }
From source file:net.sf.jabref.exporter.OpenDocumentSpreadsheetCreator.java
private static void storeOpenDocumentSpreadsheetFile(File file, InputStream source) throws Exception { try (ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) { //addResourceFile("mimetype", "/resource/ods/mimetype", out); ZipEntry ze = new ZipEntry("mimetype"); String mime = "application/vnd.oasis.opendocument.spreadsheet"; ze.setMethod(ZipEntry.STORED); ze.setSize(mime.length());//from ww w .jav a 2s . c om CRC32 crc = new CRC32(); crc.update(mime.getBytes()); ze.setCrc(crc.getValue()); out.putNextEntry(ze); for (int i = 0; i < mime.length(); i++) { out.write(mime.charAt(i)); } out.closeEntry(); ZipEntry zipEntry = new ZipEntry("content.xml"); //zipEntry.setMethod(ZipEntry.DEFLATED); out.putNextEntry(zipEntry); int c; while ((c = source.read()) >= 0) { out.write(c); } out.closeEntry(); // Add manifest (required for OOo 2.0) and "meta.xml": These are in the // resource/ods directory, and are copied verbatim into the zip file. OpenDocumentSpreadsheetCreator.addResourceFile("meta.xml", "/resource/ods/meta.xml", out); OpenDocumentSpreadsheetCreator.addResourceFile("META-INF/manifest.xml", "/resource/ods/manifest.xml", out); } }
From source file:org.danilopianini.io.FileUtilities.java
/** * Computes the CRC32 sum for a given file. * //from w ww . j ava 2s . c o m * @param f * the file * @return the CRC32 * @throws IOException * if an I/O error occurs */ public static long fileCRC32sum(final File f) throws IOException { try (final InputStream is = new FileInputStream(f)) { final CRC32 crc = new CRC32(); int val; do { val = is.read(); crc.update(val); } while (val != -1); is.close(); return crc.getValue(); } }
From source file:org.kuali.rice.krad.datadictionary.URLMonitor.java
private Long getCRC(URL zipUrl) { Long result = -1l;/*from w w w . j a v a2 s . co m*/ try { CRC32 crc = new CRC32(); CheckedInputStream cis = new CheckedInputStream(zipUrl.openStream(), crc); byte[] buffer = new byte[1024]; int length; //read the entry from zip file and extract it to disk while ((length = cis.read(buffer)) > 0) ; cis.close(); result = crc.getValue(); } catch (IOException e) { LOG.warn("Unable to calculate CRC, resource doesn't exist?", e); } return result; }