List of usage examples for com.google.common.hash Hashing md5
public static HashFunction md5()
From source file:org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFile.java
@Override public List<Pair<String, String>> countMd5Sums() throws ServerException { checkExistence();//w ww .j a v a 2s .co m if (isFile()) { return newArrayList(); } return new HashSumsCounter(this, Hashing.md5()).countHashSums(); }
From source file:io.prestosql.operator.scalar.VarbinaryFunctions.java
@Description("compute md5 hash") @ScalarFunction/* w ww . j a va 2s.co m*/ @SqlType(StandardTypes.VARBINARY) public static Slice md5(@SqlType(StandardTypes.VARBINARY) Slice slice) { return Slices.wrappedBuffer(Hashing.md5().hashBytes(slice.getBytes()).asBytes()); }
From source file:com.peppe130.rominstaller.core.FlashRecovery.java
@Override @SuppressWarnings("ConstantConditions") protected void onPostExecute(final Boolean result) { super.onPostExecute(result); Utils.ACTIVITY.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); Utils.ACTIVITY.registerReceiver(onDownloadFinishReceiver = new BroadcastReceiver() { @Override/* ww w . j a va 2 s .com*/ public void onReceive(Context context, android.content.Intent i) { mProgress.dismiss(); Utils.ACTIVITY.unregisterReceiver(onDownloadFinishReceiver); Long mDownloadID = i.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); DownloadManager.Query mQuery = new DownloadManager.Query(); mQuery.setFilterById(mDownloadID); Cursor mCursor = mDownloadManager.query(mQuery); mCursor.moveToFirst(); Integer mColumnIndex = mCursor.getColumnIndex(DownloadManager.COLUMN_STATUS); Integer mStatus; if (mCursor != null && mCursor.moveToFirst() && mColumnIndex != null) { mStatus = mCursor.getInt(mColumnIndex); switch (mStatus) { case DownloadManager.STATUS_SUCCESSFUL: if (result) { new Handler().postDelayed(new Runnable() { @Override public void run() { mProgress.title(Utils.ACTIVITY .getString(R.string.check_md5_recovery_progress_dialog_title)); mProgress.content(Utils.ACTIVITY .getString(R.string.check_md5_recovery_progress_dialog_message)); mProgress.changeDialogType(BouncingDialog.PROGRESS_TYPE); mProgress.show(); new Handler().postDelayed(new Runnable() { @Override @SuppressWarnings("ResultOfMethodCallIgnored") public void run() { try { mMD5 = Files.hash(mDownloadedFile, Hashing.md5()).toString(); if (Arrays.asList(ControlCenter.RECOVERY_MD5_LIST).contains(mMD5)) { new Handler().postDelayed(new Runnable() { @Override public void run() { mProgress.dismiss(); Utils.Sleep(500); mProgress.title(Utils.ACTIVITY.getString( R.string.flash_recovery_progress_dialog_title)); mProgress.content(Utils.ACTIVITY.getString( R.string.flash_recovery_progress_dialog_message)); mProgress.show(); if (!ControlCenter.TRIAL_MODE) { try { Command flashRecovery = new Command(0, "dd " + "if=" + mDownloadedFile + " of=" + mRecoveryPartition); RootTools.getShell(true).add(flashRecovery); new Handler().postDelayed(new Runnable() { @Override public void run() { mProgress.dismiss(); Utils.ToastLong(Utils.ACTIVITY, Utils.ACTIVITY.getString( R.string.flash_completed)); if (mHasAddOns) { cancel(true); Utils.TOAST.cancel(); new Download( Utils.DOWNLOAD_REQUEST_LIST .get(0), Utils.DOWNLOAD_DIRECTORY_LIST .get(0), Utils.DOWNLOADED_FILE_NAME_LIST .get(0), Utils.DOWNLOADED_FILE_MD5_LIST .get(0), 1).execute(); } else { Utils.SHOULD_LOCK_UI = false; Utils.ACTIVITY .invalidateOptionsMenu(); Utils.ACTIVITY.getWindow() .clearFlags( WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); } } }, 2000); } catch (TimeoutException | RootDeniedException | IOException e) { e.printStackTrace(); } } else { new Handler().postDelayed(new Runnable() { @Override public void run() { mProgress.dismiss(); Utils.ToastLong(Utils.ACTIVITY, Utils.ACTIVITY.getString( R.string.flash_completed)); if (mHasAddOns) { cancel(true); Utils.TOAST.cancel(); new Download( Utils.DOWNLOAD_REQUEST_LIST .get(0), Utils.DOWNLOAD_DIRECTORY_LIST .get(0), Utils.DOWNLOADED_FILE_NAME_LIST .get(0), Utils.DOWNLOADED_FILE_MD5_LIST .get(0), 1).execute(); } else { Utils.SHOULD_LOCK_UI = false; Utils.ACTIVITY.invalidateOptionsMenu(); Utils.ACTIVITY.getWindow().clearFlags( WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); } } }, 2000); } } }, 500); } else { mProgress.dismiss(); mDownloadedFile.delete(); Utils.Sleep(500); String mContent = (String.format( Utils.ACTIVITY.getString( R.string.recovery_md5_mismatch_dialog_message), mDownloadedFileFinalName)); BouncingDialog bouncingDialog = new BouncingDialog( Utils.ACTIVITY, BouncingDialog.ERROR_TYPE) .title(Utils.ACTIVITY.getString( R.string.recovery_md5_mismatch_dialog_title)) .content(mContent) .positiveText(Utils.ACTIVITY .getString(R.string.download_button)) .negativeText(Utils.ACTIVITY .getString(R.string.negative_button)) .onPositive( new BouncingDialog.SingleButtonCallback() { @Override public void onClick( BouncingDialog bouncingDialog1) { cancel(true); bouncingDialog1.dismiss(); new FlashRecovery(mRequest, mDownloadDirectory, mDownloadedFileFinalName, mRecoveryPartition, mHasAddOns).execute(); } }) .onNegative( new BouncingDialog.SingleButtonCallback() { @Override public void onClick( BouncingDialog bouncingDialog1) { bouncingDialog1.dismiss(); new Handler().postDelayed( new Runnable() { @Override public void run() { Utils.SHOULD_LOCK_UI = false; Utils.ACTIVITY .invalidateOptionsMenu(); Utils.ToastLong( Utils.ACTIVITY, Utils.ACTIVITY .getString( R.string.recovery_needed)); } }, 300); } }); bouncingDialog.setCancelable(false); bouncingDialog.show(); } } catch (IOException e) { e.printStackTrace(); } } }, 500); } }, 500); } else { BouncingDialog bouncingDialog = new BouncingDialog(Utils.ACTIVITY, BouncingDialog.ERROR_TYPE) .title(Utils.ACTIVITY.getString(R.string.no_root_access_dialog_title)) .content(Utils.ACTIVITY .getString(R.string.no_root_access_dialog_message)) .positiveText(Utils.ACTIVITY.getString(R.string.close_button)) .onPositive(new BouncingDialog.SingleButtonCallback() { @Override public void onClick(BouncingDialog bouncingDialog1) { Utils.ACTIVITY.finishAffinity(); } }); bouncingDialog.setCancelable(false); bouncingDialog.show(); } break; } } } }, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
From source file:com.facebook.buck.core.build.engine.buildinfo.BuildInfoRecorder.java
public HashCode getOutputHash(FileHashCache fileHashCache) throws IOException { Hasher hasher = Hashing.md5().newHasher(); for (Path path : getRecordedPaths()) { hasher.putBytes(fileHashCache.get(projectFilesystem.resolve(path)).asBytes()); }//from w ww . j av a 2s . co m return hasher.hash(); }
From source file:com.android.tools.idea.gradle.project.AndroidGradleProjectData.java
@NotNull private static byte[] createChecksum(@NotNull File file) throws IOException { // For files tracked by the IDE we get the content from the virtual files, otherwise we revert to io. VirtualFile vf = VfsUtil.findFileByIoFile(file, true); byte[] data = new byte[] {}; if (vf != null) { vf.refresh(false, false);/*w w w . j a va2s. co m*/ if (vf.exists()) { data = vf.contentsToByteArray(); } } else if (file.exists()) { data = Files.toByteArray(file); } return Hashing.md5().hashBytes(data).asBytes(); }
From source file:com.bouncestorage.chaoshttpproxy.ChaosHttpProxyHandler.java
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse servletResponse) throws IOException { baseRequest.setHandled(true);/* w ww . j ava 2s .com*/ // CONNECT is not supported pending implementation of MITM HTTPS if (request.getMethod().equals("CONNECT")) { logger.debug("CONNECT is not supported"); servletResponse.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return; } Failure failure = supplier.get(); logger.debug("request: {}", request); logger.debug("Failure: {}", failure); try (InputStream is = request.getInputStream(); OutputStream os = servletResponse.getOutputStream()) { HostAndPort hostAndPort = HostAndPort.fromString(request.getHeader(HttpHeaders.HOST)); String queryString = request.getQueryString(); URI uri; try { uri = new URI(request.getScheme(), /*userInfo=*/ null, hostAndPort.getHostText(), hostAndPort.hasPort() ? hostAndPort.getPort() : 80, request.getRequestURI(), queryString, /*fragment=*/ null); } catch (URISyntaxException use) { throw new IOException(use); } logger.debug("uri: {}", uri); URI redirectedUri = redirects.get(uri); if (redirectedUri != null) { // TODO: parameters uri = redirectedUri; logger.debug("redirected uri: {}", uri); } switch (failure) { case HTTP_301: case HTTP_302: case HTTP_303: case HTTP_307: case HTTP_308: servletResponse.setStatus(failure.getResponseCode()); URI redirectUri; try { redirectUri = new URI(request.getScheme(), /*userInfo=*/ null, hostAndPort.getHostText(), hostAndPort.hasPort() ? hostAndPort.getPort() : 80, "/" + UUID.randomUUID().toString(), /*query=*/ null, /*fragment=*/ null); } catch (URISyntaxException use) { throw new IOException(use); } redirects.put(redirectUri, uri); servletResponse.addHeader(HttpHeaders.LOCATION, redirectUri.toString()); return; case HTTP_408: case HTTP_500: case HTTP_503: case HTTP_504: servletResponse.setStatus(failure.getResponseCode()); return; case TIMEOUT: Uninterruptibles.sleepUninterruptibly(Long.MAX_VALUE, TimeUnit.DAYS); return; default: break; } InputStreamResponseListener listener = new InputStreamResponseListener(); InputStream iss = failure == Failure.PARTIAL_REQUEST ? // TODO: random limit ByteStreams.limit(is, 1024) : is; org.eclipse.jetty.client.api.Request clientRequest = client.newRequest(uri.toString()) .method(request.getMethod()); long userContentLength = -1; for (String headerName : Collections.list(request.getHeaderNames())) { if (headerName.equalsIgnoreCase(HttpHeaders.EXPECT) || headerName.equalsIgnoreCase("Proxy-Connection")) { continue; } String headerValue = request.getHeader(headerName); logger.trace("{}: {}", headerName, headerValue); if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_MD5) && failure == Failure.CORRUPT_REQUEST_CONTENT_MD5) { headerValue = headerValue.toUpperCase(); } if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH)) { userContentLength = Long.parseLong(headerValue); } clientRequest.header(headerName, headerValue); } // Work around Jetty bug that strips Content-Length // https://bugs.eclipse.org/bugs/show_bug.cgi?id=475613. final long length = userContentLength; clientRequest.content(new InputStreamContentProvider(iss) { @Override public long getLength() { return length != -1 ? length : super.getLength(); } }); clientRequest.send(listener); if (failure == Failure.PARTIAL_REQUEST) { return; } Response response; try { response = listener.get(Long.MAX_VALUE, TimeUnit.SECONDS); } catch (ExecutionException | InterruptedException | TimeoutException e) { throw new IOException(e); } int status = response.getStatus(); logger.trace("status: {}", status); servletResponse.setStatus(status); List<HttpField> headers = Lists.newArrayList(response.getHeaders()); if (failure == Failure.REORDER_HEADERS) { Collections.shuffle(headers); } for (HttpField field : headers) { String header = field.getName(); String value = field.getValue(); logger.trace("header: {}: {}", header, value); switch (failure) { case CHANGE_HEADER_CASE: // TODO: randomly change between upper- and lower-case header = header.toUpperCase(); break; case CORRUPT_RESPONSE_CONTENT_MD5: if (header.equals(HttpHeaders.CONTENT_MD5)) { value = BaseEncoding.base64().encode(new byte[Hashing.md5().bits() / 8]); } break; default: break; } servletResponse.addHeader(header, value); } try (InputStream responseContent = listener.getInputStream()) { switch (failure) { case PARTIAL_RESPONSE: byte[] array = new byte[1024]; int count = responseContent.read(array); if (count != -1) { // TODO: randomly read n - 1 bytes os.write(array, 0, count / 2); os.flush(); } return; case SLOW_RESPONSE: for (int i = 0; i < 10; ++i) { int ch = responseContent.read(); if (ch == -1) { break; } os.write(ch); os.flush(); Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); } break; default: break; } ByteStreams.copy(responseContent, os); } } }
From source file:com.google.gerrit.server.change.FileContentUtil.java
private static String randSuffix() { // Produce a random suffix that is difficult (or nearly impossible) // for an attacker to guess in advance. This reduces the risk that // an attacker could upload a *.class file and have us send a ZIP // that can be invoked through an applet tag in the victim's browser. ////ww w . j av a 2 s. c o m Hasher h = Hashing.md5().newHasher(); byte[] buf = new byte[8]; NB.encodeInt64(buf, 0, TimeUtil.nowMs()); h.putBytes(buf); rng.nextBytes(buf); h.putBytes(buf); return h.hash().toString(); }
From source file:org.dllearner.algorithms.isle.CrossValidation.java
public CrossValidation(AbstractCELA la, AbstractLearningProblem lp, AbstractReasonerComponent rs, int folds, boolean leaveOneOut) { DecimalFormat df = new DecimalFormat(); // the training and test sets used later on List<Set<Individual>> trainingSetsPos = new LinkedList<Set<Individual>>(); List<Set<Individual>> trainingSetsNeg = new LinkedList<Set<Individual>>(); List<Set<Individual>> testSetsPos = new LinkedList<Set<Individual>>(); List<Set<Individual>> testSetsNeg = new LinkedList<Set<Individual>>(); // get examples and shuffle them too Set<Individual> posExamples; Set<Individual> negExamples; if (lp instanceof PosNegLP) { posExamples = ((PosNegLP) lp).getPositiveExamples(); negExamples = ((PosNegLP) lp).getNegativeExamples(); } else if (lp instanceof PosOnlyLP) { posExamples = ((PosOnlyLP) lp).getPositiveExamples(); negExamples = new HashSet<Individual>(); } else {/*from www . j a v a 2 s . c om*/ throw new IllegalArgumentException("Only PosNeg and PosOnly learning problems are supported"); } List<Individual> posExamplesList = new LinkedList<Individual>(posExamples); List<Individual> negExamplesList = new LinkedList<Individual>(negExamples); Collections.shuffle(posExamplesList, new Random(1)); Collections.shuffle(negExamplesList, new Random(2)); // sanity check whether nr. of folds makes sense for this benchmark if (!leaveOneOut && (posExamples.size() < folds && negExamples.size() < folds)) { System.out.println("The number of folds is higher than the number of " + "positive/negative examples. This can result in empty test sets. Exiting."); System.exit(0); } if (leaveOneOut) { // note that leave-one-out is not identical to k-fold with // k = nr. of examples in the current implementation, because // with n folds and n examples there is no guarantee that a fold // is never empty (this is an implementation issue) int nrOfExamples = posExamples.size() + negExamples.size(); for (int i = 0; i < nrOfExamples; i++) { // ... } System.out.println("Leave-one-out not supported yet."); System.exit(1); } else { // calculating where to split the sets, ; note that we split // positive and negative examples separately such that the // distribution of positive and negative examples remains similar // (note that there are better but more complex ways to implement this, // which guarantee that the sum of the elements of a fold for pos // and neg differs by at most 1 - it can differ by 2 in our implementation, // e.g. with 3 folds, 4 pos. examples, 4 neg. examples) int[] splitsPos = calculateSplits(posExamples.size(), folds); int[] splitsNeg = calculateSplits(negExamples.size(), folds); // System.out.println(splitsPos[0]); // System.out.println(splitsNeg[0]); // calculating training and test sets for (int i = 0; i < folds; i++) { Set<Individual> testPos = getTestingSet(posExamplesList, splitsPos, i); Set<Individual> testNeg = getTestingSet(negExamplesList, splitsNeg, i); testSetsPos.add(i, testPos); testSetsNeg.add(i, testNeg); trainingSetsPos.add(i, getTrainingSet(posExamples, testPos)); trainingSetsNeg.add(i, getTrainingSet(negExamples, testNeg)); } } // run the algorithm for (int currFold = 0; currFold < folds; currFold++) { Set<String> pos = Datastructures.individualSetToStringSet(trainingSetsPos.get(currFold)); Set<String> neg = Datastructures.individualSetToStringSet(trainingSetsNeg.get(currFold)); if (lp instanceof PosNegLP) { ((PosNegLP) lp).setPositiveExamples(trainingSetsPos.get(currFold)); ((PosNegLP) lp).setNegativeExamples(trainingSetsNeg.get(currFold)); } else if (lp instanceof PosOnlyLP) { ((PosOnlyLP) lp).setPositiveExamples(new TreeSet<Individual>(trainingSetsPos.get(currFold))); } try { lp.init(); la.init(); } catch (ComponentInitException e) { // TODO Auto-generated catch block e.printStackTrace(); } long algorithmStartTime = System.nanoTime(); la.start(); long algorithmDuration = System.nanoTime() - algorithmStartTime; runtime.addNumber(algorithmDuration / (double) 1000000000); Description concept = la.getCurrentlyBestDescription(); Set<Individual> tmp = rs.hasType(concept, testSetsPos.get(currFold)); Set<Individual> tmp2 = Helper.difference(testSetsPos.get(currFold), tmp); Set<Individual> tmp3 = rs.hasType(concept, testSetsNeg.get(currFold)); outputWriter("test set errors pos: " + tmp2); outputWriter("test set errors neg: " + tmp3); // calculate training accuracies int trainingCorrectPosClassified = getCorrectPosClassified(rs, concept, trainingSetsPos.get(currFold)); int trainingCorrectNegClassified = getCorrectNegClassified(rs, concept, trainingSetsNeg.get(currFold)); int trainingCorrectExamples = trainingCorrectPosClassified + trainingCorrectNegClassified; double trainingAccuracy = 100 * ((double) trainingCorrectExamples / (trainingSetsPos.get(currFold).size() + trainingSetsNeg.get(currFold).size())); HashFunction hf = Hashing.md5(); accuracyTraining.addNumber(trainingAccuracy); // calculate test accuracies int correctPosClassified = getCorrectPosClassified(rs, concept, testSetsPos.get(currFold)); int correctNegClassified = getCorrectNegClassified(rs, concept, testSetsNeg.get(currFold)); int correctExamples = correctPosClassified + correctNegClassified; double currAccuracy = 100 * ((double) correctExamples / (testSetsPos.get(currFold).size() + testSetsNeg.get(currFold).size())); accuracy.addNumber(currAccuracy); // calculate training F-Score int negAsPosTraining = rs.hasType(concept, trainingSetsNeg.get(currFold)).size(); double precisionTraining = trainingCorrectPosClassified + negAsPosTraining == 0 ? 0 : trainingCorrectPosClassified / (double) (trainingCorrectPosClassified + negAsPosTraining); double recallTraining = trainingCorrectPosClassified / (double) trainingSetsPos.get(currFold).size(); fMeasureTraining.addNumber(100 * Heuristics.getFScore(recallTraining, precisionTraining)); // calculate test F-Score int negAsPos = rs.hasType(concept, testSetsNeg.get(currFold)).size(); double precision = correctPosClassified + negAsPos == 0 ? 0 : correctPosClassified / (double) (correctPosClassified + negAsPos); double recall = correctPosClassified / (double) testSetsPos.get(currFold).size(); // System.out.println(precision);System.out.println(recall); fMeasure.addNumber(100 * Heuristics.getFScore(recall, precision)); length.addNumber(concept.getLength()); outputWriter("fold " + currFold + ":"); outputWriter(" training: " + pos.size() + " positive and " + neg.size() + " negative examples"); outputWriter(" testing: " + correctPosClassified + "/" + testSetsPos.get(currFold).size() + " correct positives, " + correctNegClassified + "/" + testSetsNeg.get(currFold).size() + " correct negatives"); outputWriter(" concept: " + concept); outputWriter(" accuracy: " + df.format(currAccuracy) + "% (" + df.format(trainingAccuracy) + "% on training set)"); outputWriter(" length: " + df.format(concept.getLength())); outputWriter(" runtime: " + df.format(algorithmDuration / (double) 1000000000) + "s"); } outputWriter(""); outputWriter("Finished " + folds + "-folds cross-validation."); outputWriter("runtime: " + statOutput(df, runtime, "s")); outputWriter("length: " + statOutput(df, length, "")); outputWriter("F-Measure on training set: " + statOutput(df, fMeasureTraining, "%")); outputWriter("F-Measure: " + statOutput(df, fMeasure, "%")); outputWriter("predictive accuracy on training set: " + statOutput(df, accuracyTraining, "%")); outputWriter("predictive accuracy: " + statOutput(df, accuracy, "%")); }
From source file:com.peppe130.fireinstaller.core.Download.java
@Override @SuppressWarnings("ConstantConditions") protected void onPostExecute(String result) { super.onPostExecute(result); Utils.ACTIVITY.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); Utils.ACTIVITY.registerReceiver(onDownloadFinishReceiver = new BroadcastReceiver() { @Override//from w w w . j a va 2 s . c o m public void onReceive(Context context, Intent i) { Utils.ACTIVITY.unregisterReceiver(onDownloadFinishReceiver); Long mDownloadID = i.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); DownloadManager.Query mQuery = new DownloadManager.Query(); mQuery.setFilterById(mDownloadID); Cursor mCursor = mDownloadManager.query(mQuery); mCursor.moveToFirst(); Integer mColumnIndex = mCursor.getColumnIndex(DownloadManager.COLUMN_STATUS); Integer mStatus; if (mCursor != null && mCursor.moveToFirst() && mColumnIndex != null) { mStatus = mCursor.getInt(mColumnIndex); switch (mStatus) { case DownloadManager.STATUS_SUCCESSFUL: if (mDownloadedFileMD5 != null && mDownloadedFileMD5.trim().length() != 0) { try { String mContent = (String.format( Utils.ACTIVITY.getString(R.string.downloaded_file_md5_check), mDownloadedFileFinalName)); Utils.ToastShort(Utils.ACTIVITY, mContent); mHashCode = Files.hash(mDownloadedFile, Hashing.md5()); if (mHashCode.toString().equalsIgnoreCase(mDownloadedFileMD5)) { new Handler().postDelayed(new Runnable() { @Override public void run() { Utils.TOAST.cancel(); new Handler().postDelayed(new Runnable() { @Override public void run() { mProgress.dismiss(); } }, 300); } }, 500); if (mNextDownloadIndex != null && mNextDownloadIndex < Utils.DOWNLOAD_REQUEST_LIST.size()) { new Handler().postDelayed(new Runnable() { @Override @SuppressWarnings("LoopStatementThatDoesntLoop") public void run() { cancel(true); for (Integer mInt = mNextDownloadIndex; mInt < Utils.DOWNLOAD_REQUEST_LIST .size(); mInt++) { new Download(Utils.DOWNLOAD_REQUEST_LIST.get(mInt), Utils.DOWNLOAD_DIRECTORY_LIST.get(mInt), Utils.DOWNLOADED_FILE_NAME_LIST.get(mInt), Utils.DOWNLOADED_FILE_MD5_LIST.get(mInt), ++mInt) .execute(); break; } } }, 500); } else { new Handler().postDelayed(new Runnable() { @Override public void run() { cancel(true); Utils.SHOULD_LOCK_UI = false; Utils.ACTIVITY.invalidateOptionsMenu(); new Handler().postDelayed(new Runnable() { @Override public void run() { Utils.ToastLong(Utils.ACTIVITY, Utils.ACTIVITY .getString(R.string.download_completed)); Utils.ACTIVITY.getWindow().clearFlags( WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); } }, 300); ClearArrays(); } }, 1000); } } else { new Handler().postDelayed(new Runnable() { @Override public void run() { Utils.TOAST.cancel(); new Handler().postDelayed(new Runnable() { @Override public void run() { mProgress.dismiss(); } }, 300); } }, 500); new Handler().postDelayed(new Runnable() { @Override @SuppressWarnings("ResultOfMethodCallIgnored") public void run() { mDownloadedFile.delete(); Utils.ACTIVITY.getWindow() .clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); String mContent = (String.format( Utils.ACTIVITY.getString( R.string.downloaded_file_md5_mismatch_dialog_message), mDownloadedFileFinalName)); BouncingDialog bouncingDialog = new BouncingDialog(Utils.ACTIVITY, BouncingDialog.ERROR_TYPE) .title(Utils.ACTIVITY.getString( R.string.downloaded_file_md5_mismatch_dialog_title)) .content(mContent) .positiveText(Utils.ACTIVITY .getString(R.string.download_button)) .negativeText(Utils.ACTIVITY .getString(R.string.negative_button)) .onPositive(new BouncingDialog.SingleButtonCallback() { @Override public void onClick( BouncingDialog bouncingDialog1) { cancel(true); bouncingDialog1.dismiss(); new Download(mRequest, mDownloadDirectory, mDownloadedFileFinalName, mDownloadedFileMD5, mNextDownloadIndex) .execute(); } }) .onNegative(new BouncingDialog.SingleButtonCallback() { @Override @SuppressWarnings("LoopStatementThatDoesntLoop") public void onClick( final BouncingDialog bouncingDialog1) { if (mNextDownloadIndex != null && mNextDownloadIndex < Utils.DOWNLOAD_REQUEST_LIST .size()) { new Handler().postDelayed(new Runnable() { @Override public void run() { cancel(true); bouncingDialog1.dismiss(); for (Integer mInt = mNextDownloadIndex; mInt < Utils.DOWNLOAD_REQUEST_LIST .size(); mInt++) { new Download( Utils.DOWNLOAD_REQUEST_LIST .get(mInt), Utils.DOWNLOAD_DIRECTORY_LIST .get(mInt), Utils.DOWNLOADED_FILE_NAME_LIST .get(mInt), Utils.DOWNLOADED_FILE_MD5_LIST .get(mInt), ++mInt).execute(); break; } } }, 500); } else { cancel(true); bouncingDialog1.dismiss(); Utils.SHOULD_LOCK_UI = false; Utils.ACTIVITY.invalidateOptionsMenu(); } } }); bouncingDialog.setCancelable(false); bouncingDialog.show(); } }, 1000); } } catch (IOException e) { e.printStackTrace(); } } else { mProgress.dismiss(); Boolean mBoolean = mNextDownloadIndex != null && mNextDownloadIndex < Utils.DOWNLOAD_REQUEST_LIST.size(); Boolean mBoolean2 = mNextDownloadIndex != null && mNextDownloadIndex < Utils.DOWNLOADED_FILE_MD5_LIST.size() && Utils.DOWNLOADED_FILE_MD5_LIST.get(mNextDownloadIndex) != null && Utils.DOWNLOADED_FILE_MD5_LIST.get(mNextDownloadIndex).trim().length() != 0; if (mBoolean && mBoolean2) { new Handler().postDelayed(new Runnable() { @Override @SuppressWarnings("LoopStatementThatDoesntLoop") public void run() { cancel(true); for (Integer mInt = mNextDownloadIndex; mInt < Utils.DOWNLOAD_REQUEST_LIST .size(); mInt++) { new Download(Utils.DOWNLOAD_REQUEST_LIST.get(mInt), Utils.DOWNLOAD_DIRECTORY_LIST.get(mInt), Utils.DOWNLOADED_FILE_NAME_LIST.get(mInt), Utils.DOWNLOADED_FILE_MD5_LIST.get(mInt), ++mInt).execute(); break; } } }, 500); } else if (!mBoolean && mBoolean2) { new Handler().postDelayed(new Runnable() { @Override @SuppressWarnings("LoopStatementThatDoesntLoop") public void run() { cancel(true); for (Integer mInt = mNextDownloadIndex; mInt < Utils.DOWNLOAD_REQUEST_LIST .size(); mInt++) { new Download(Utils.DOWNLOAD_REQUEST_LIST.get(mInt), Utils.DOWNLOAD_DIRECTORY_LIST.get(mInt), Utils.DOWNLOADED_FILE_NAME_LIST.get(mInt), Utils.DOWNLOADED_FILE_MD5_LIST.get(mInt)).execute(); break; } } }, 500); } else if (mBoolean && !mBoolean2) { new Handler().postDelayed(new Runnable() { @Override @SuppressWarnings("LoopStatementThatDoesntLoop") public void run() { cancel(true); for (Integer mInt = mNextDownloadIndex; mInt < Utils.DOWNLOAD_REQUEST_LIST .size(); mInt++) { new Download(Utils.DOWNLOAD_REQUEST_LIST.get(mInt), Utils.DOWNLOAD_DIRECTORY_LIST.get(mInt), Utils.DOWNLOADED_FILE_NAME_LIST.get(mInt), null, ++mInt) .execute(); break; } } }, 500); } else { if (mStartCheckFile != null && mStartCheckFile) { cancel(true); if (!ControlCenter.TEST_MODE) { Utils.SetZipFile(mDownloadedFile); new CheckFile().execute(); } else { Utils.SHOULD_LOCK_UI = false; Utils.ACTIVITY.invalidateOptionsMenu(); Utils.ACTIVITY.getWindow() .clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); Utils.ToastLong(Utils.ACTIVITY, Utils.ACTIVITY.getString(R.string.disable_test_mode_checkfile)); } ClearArrays(); } else { new Handler().postDelayed(new Runnable() { @Override public void run() { cancel(true); Utils.SHOULD_LOCK_UI = false; Utils.ACTIVITY.invalidateOptionsMenu(); Utils.ToastLong(Utils.ACTIVITY, Utils.ACTIVITY.getString(R.string.download_completed)); Utils.ACTIVITY.getWindow() .clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); ClearArrays(); } }, 500); } } } break; } } } }, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
From source file:org.eclipse.che.api.project.server.EditorWorkingCopyManager.java
private boolean isWorkingCopyHasUnsavedData(String originalFilePath) { try {/*ww w . j a v a2s . c om*/ EditorWorkingCopy workingCopy = workingCopiesStorage.get(originalFilePath); if (workingCopy == null) { return false; } FileEntry originalFile = projectManagerProvider.get().asFile(originalFilePath); if (originalFile == null) { return false; } String workingCopyContent = workingCopy.getContentAsString(); String originalFileContent = originalFile.getVirtualFile().getContentAsString(); if (workingCopyContent == null || originalFileContent == null) { return false; } String workingCopyHash = Hashing.md5().hashString(workingCopyContent, defaultCharset()).toString(); String originalFileHash = Hashing.md5().hashString(originalFileContent, defaultCharset()).toString(); return !Objects.equals(workingCopyHash, originalFileHash); } catch (NotFoundException | ServerException | ForbiddenException e) { LOG.error(e.getLocalizedMessage()); } return false; }