Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(701)

Unified Diff: mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/FileHelper.java

Issue 775343004: Move //mojo/shell to //shell (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/FileHelper.java
diff --git a/mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/FileHelper.java b/mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/FileHelper.java
deleted file mode 100644
index 70f95e1f13dc5e37248b04ee9c123ba7fb10a00b..0000000000000000000000000000000000000000
--- a/mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/FileHelper.java
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package org.chromium.mojo_shell_apk;
-
-import android.content.Context;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-/**
- * Helper methods for file extraction from APK assets and zip archives.
- */
-class FileHelper {
- // Size of the buffer used in streaming file operations.
- private static final int BUFFER_SIZE = 1024 * 1024;
- // Prefix used when naming temporary files.
- private static final String TEMP_FILE_PREFIX = "temp-";
-
- static File extractFromAssets(Context context, String assetName, File outputDirectory)
- throws IOException, FileNotFoundException {
- // Make the original filename part of the temp file name.
- // TODO(ppi): do we need to sanitize the suffix?
- String suffix = "-" + assetName;
- File outputFile = File.createTempFile(TEMP_FILE_PREFIX, suffix, outputDirectory);
- BufferedInputStream inputStream = new BufferedInputStream(
- context.getAssets().open(assetName));
- writeStreamToFile(inputStream, outputFile);
- inputStream.close();
- return outputFile;
- }
-
- /**
- * Extracts the file of the given extension from the archive. Throws FileNotFoundException if no
- * matching file is found.
- */
- static File extractFromArchive(File archive, String suffixToMatch,
- File outputDirectory) throws IOException, FileNotFoundException {
- ZipInputStream zip = new ZipInputStream(new BufferedInputStream(new FileInputStream(
- archive)));
- ZipEntry entry;
- while ((entry = zip.getNextEntry()) != null) {
- if (entry.getName().endsWith(suffixToMatch)) {
- // Make the original filename part of the temp file name.
- // TODO(ppi): do we need to sanitize the suffix?
- String suffix = "-" + new File(entry.getName()).getName();
- File extractedFile = File.createTempFile(TEMP_FILE_PREFIX, suffix,
- outputDirectory);
- writeStreamToFile(zip, extractedFile);
- zip.close();
- return extractedFile;
- }
- }
- zip.close();
- throw new FileNotFoundException();
- }
-
- /**
- * Deletes a file or directory. Directory will be deleted even if not empty.
- */
- static void deleteRecursively(File file) {
- if (file.isDirectory()) {
- for (File child : file.listFiles()) {
- deleteRecursively(child);
- }
- }
- file.delete();
- }
-
- private static void writeStreamToFile(InputStream inputStream, File outputFile)
- throws IOException {
- byte[] buffer = new byte[BUFFER_SIZE];
- OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
- int read;
- while ((read = inputStream.read(buffer, 0, BUFFER_SIZE)) > 0) {
- outputStream.write(buffer, 0, read);
- }
- outputStream.close();
- }
-}

Powered by Google App Engine
This is Rietveld 408576698