List of usage examples for java.util.zip CRC32 getValue
@Override public long getValue()
From source file:me.j360.dubbo.modules.util.text.HashUtil.java
/** * crc32int, ?./*from www . ja va 2s . co m*/ * * Guavacrc32, longJDK */ public static int crc32AsInt(@NotNull byte[] input) { CRC32 crc32 = new CRC32(); crc32.update(input); // CRC32 ? 32bit intCheckSum??long?? return (int) crc32.getValue(); }
From source file:com.aol.advertising.qiao.util.CommonUtils.java
public static long checkSum(byte[] bytes) { CRC32 crc = new CRC32(); crc.update(bytes);//from w w w . j av a 2s. com return crc.getValue(); }
From source file:Main.java
public static String getCRC32(File file) { CRC32 crc32 = new CRC32(); CheckedInputStream checkedinputstream = null; String crc = null;//from www . j a v a2 s .c o m try { checkedinputstream = new CheckedInputStream(new FileInputStream(file), crc32); byte[] buf = new byte[1024]; while (checkedinputstream.read(buf) >= 0) { } crc = Long.toHexString(crc32.getValue()).toUpperCase(); } catch (Exception e) { Log.w(TAG, e); Log.e("WxException", e.getMessage(), e); } finally { if (checkedinputstream != null) { try { checkedinputstream.close(); } catch (IOException e) { } } } return crc; }
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);//from w ww. jav a 2 s.c om return sum_control.getValue(); }
From source file:com.aimluck.eip.util.ALCellularUtils.java
/** * ?? ID ??? URL ??????//from www . jav a2 s . c o m * * @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:com.petercho.Encoder.java
public static long checksumCRC32(String text) { CRC32 crc = new CRC32(); try (InputStream is = new ByteArrayInputStream(text.getBytes(DEFAULT_ENCODING))) { checksum(is, crc);//from w w w . j a va 2 s. c o m } catch (IOException e) { throw new IllegalStateException("Error getting checksum, e:" + e, e); } return crc.getValue(); }
From source file:com.jhash.oimadmin.Utils.java
public static void createJarFileFromContent(Map<String, byte[]> content, String[] fileSequence, String jarFileName) {//from ww w . j av a 2 s. c o m logger.trace("createJarFileFromContent({},{})", content, jarFileName); logger.trace("Trying to create a new jar file"); try (ZipOutputStream jarFileOutputStream = new ZipOutputStream(new FileOutputStream(jarFileName))) { jarFileOutputStream.setMethod(ZipOutputStream.STORED); for (String jarItem : fileSequence) { logger.trace("Processing item {}", jarItem); byte[] fileContent = content.get(jarItem); if (fileContent == null) throw new NullPointerException("Failed to locate content for file " + jarItem); JarEntry pluginXMLFileEntry = new JarEntry(jarItem); pluginXMLFileEntry.setTime(System.currentTimeMillis()); pluginXMLFileEntry.setSize(fileContent.length); pluginXMLFileEntry.setCompressedSize(fileContent.length); CRC32 crc = new CRC32(); crc.update(fileContent); pluginXMLFileEntry.setCrc(crc.getValue()); jarFileOutputStream.putNextEntry(pluginXMLFileEntry); jarFileOutputStream.write(fileContent); jarFileOutputStream.closeEntry(); } } catch (Exception exception) { throw new OIMAdminException("Failed to create the Jar file " + jarFileName, exception); } }
From source file:org.mariotaku.twidere.util.TwitterContentUtils.java
public static boolean isOfficialKey(final Context context, final String consumerKey, final String consumerSecret) { if (context == null || consumerKey == null || consumerSecret == null) return false; final String[] keySecrets = context.getResources() .getStringArray(R.array.values_official_consumer_secret_crc32); final CRC32 crc32 = new CRC32(); final byte[] consumerSecretBytes = consumerSecret.getBytes(Charset.forName("UTF-8")); crc32.update(consumerSecretBytes, 0, consumerSecretBytes.length); final long value = crc32.getValue(); crc32.reset();//from w ww. ja v a2 s. c o m for (final String keySecret : keySecrets) { if (Long.parseLong(keySecret, 16) == value) return true; } return false; }
From source file:org.mariotaku.twidere.util.TwitterContentUtils.java
public static String getOfficialKeyName(final Context context, final String consumerKey, final String consumerSecret) { if (context == null || consumerKey == null || consumerSecret == null) return null; final String[] keySecrets = context.getResources() .getStringArray(R.array.values_official_consumer_secret_crc32); final String[] keyNames = context.getResources().getStringArray(R.array.names_official_consumer_secret); final CRC32 crc32 = new CRC32(); final byte[] consumerSecretBytes = consumerSecret.getBytes(Charset.forName("UTF-8")); crc32.update(consumerSecretBytes, 0, consumerSecretBytes.length); final long value = crc32.getValue(); crc32.reset();/*from w w w.j a va 2 s . c o m*/ for (int i = 0, j = keySecrets.length; i < j; i++) { if (Long.parseLong(keySecrets[i], 16) == value) return keyNames[i]; } return null; }
From source file:org.mariotaku.twidere.util.TwitterContentUtils.java
@NonNull public static ConsumerKeyType getOfficialKeyType(final Context context, final String consumerKey, final String consumerSecret) { if (context == null || consumerKey == null || consumerSecret == null) { return ConsumerKeyType.UNKNOWN; }/*from www . ja va 2s . co m*/ final String[] keySecrets = context.getResources() .getStringArray(R.array.values_official_consumer_secret_crc32); final String[] keyNames = context.getResources().getStringArray(R.array.types_official_consumer_secret); final CRC32 crc32 = new CRC32(); final byte[] consumerSecretBytes = consumerSecret.getBytes(Charset.forName("UTF-8")); crc32.update(consumerSecretBytes, 0, consumerSecretBytes.length); final long value = crc32.getValue(); crc32.reset(); for (int i = 0, j = keySecrets.length; i < j; i++) { if (Long.parseLong(keySecrets[i], 16) == value) { return ConsumerKeyType.parse(keyNames[i]); } } return ConsumerKeyType.UNKNOWN; }