Java Code Examples for com.google.android.vending.expansion.downloader.Helpers#isFilenameValid()
The following examples show how to use
com.google.android.vending.expansion.downloader.Helpers#isFilenameValid() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadThread.java From QtAndroidTools with MIT License | 4 votes |
/** * Prepare the destination file to receive data. If the file already exists, * we'll set up appropriately for resumption. */ private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { if (state.mFilename != null) { // only true if we've already run a // thread for this download if (!Helpers.isFilenameValid(state.mFilename)) { // this should never happen throw new StopRequest(DownloaderService.STATUS_FILE_ERROR, "found invalid internal destination filename"); } // We're resuming a download that got interrupted File f = new File(state.mFilename); if (f.exists()) { long fileLength = f.length(); if (fileLength == 0) { // The download hadn't actually started, we can restart from // scratch f.delete(); state.mFilename = null; } else if (mInfo.mETag == null) { // This should've been caught upon failure f.delete(); throw new StopRequest(DownloaderService.STATUS_CANNOT_RESUME, "Trying to resume a download that can't be resumed"); } else { // All right, we'll be able to resume this download try { state.mStream = new FileOutputStream(state.mFilename, true); } catch (FileNotFoundException exc) { throw new StopRequest(DownloaderService.STATUS_FILE_ERROR, "while opening destination for resuming: " + exc.toString(), exc); } innerState.mBytesSoFar = (int) fileLength; if (mInfo.mTotalBytes != -1) { innerState.mHeaderContentLength = Long.toString(mInfo.mTotalBytes); } innerState.mHeaderETag = mInfo.mETag; innerState.mContinuingDownload = true; } } } if (state.mStream != null) { closeDestination(state); } }
Example 2
Source File: DownloadThread.java From play-apk-expansion with Apache License 2.0 | 4 votes |
/** * Prepare the destination file to receive data. If the file already exists, * we'll set up appropriately for resumption. */ private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { if (state.mFilename != null) { // only true if we've already run a // thread for this download if (!Helpers.isFilenameValid(state.mFilename)) { // this should never happen throw new StopRequest(DownloaderService.STATUS_FILE_ERROR, "found invalid internal destination filename"); } // We're resuming a download that got interrupted File f = new File(state.mFilename); if (f.exists()) { long fileLength = f.length(); if (fileLength == 0) { // The download hadn't actually started, we can restart from // scratch f.delete(); state.mFilename = null; } else if (mInfo.mETag == null) { // This should've been caught upon failure f.delete(); throw new StopRequest(DownloaderService.STATUS_CANNOT_RESUME, "Trying to resume a download that can't be resumed"); } else { // All right, we'll be able to resume this download try { state.mStream = new FileOutputStream(state.mFilename, true); } catch (FileNotFoundException exc) { throw new StopRequest(DownloaderService.STATUS_FILE_ERROR, "while opening destination for resuming: " + exc.toString(), exc); } innerState.mBytesSoFar = (int) fileLength; if (mInfo.mTotalBytes != -1) { innerState.mHeaderContentLength = Long.toString(mInfo.mTotalBytes); } innerState.mHeaderETag = mInfo.mETag; innerState.mContinuingDownload = true; } } } if (state.mStream != null) { closeDestination(state); } }
Example 3
Source File: DownloadThread.java From travelguide with Apache License 2.0 | 4 votes |
/** * Prepare the destination file to receive data. If the file already exists, * we'll set up appropriately for resumption. */ private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { if (state.mFilename != null) { // only true if we've already run a // thread for this download if (!Helpers.isFilenameValid(state.mFilename)) { // this should never happen throw new StopRequest(DownloaderService.STATUS_FILE_ERROR, "found invalid internal destination filename"); } // We're resuming a download that got interrupted File f = new File(state.mFilename); if (f.exists()) { long fileLength = f.length(); if (fileLength == 0) { // The download hadn't actually started, we can restart from // scratch f.delete(); state.mFilename = null; } else if (mInfo.mETag == null) { // This should've been caught upon failure f.delete(); throw new StopRequest(DownloaderService.STATUS_CANNOT_RESUME, "Trying to resume a download that can't be resumed"); } else { // All right, we'll be able to resume this download try { state.mStream = new FileOutputStream(state.mFilename, true); } catch (FileNotFoundException exc) { throw new StopRequest(DownloaderService.STATUS_FILE_ERROR, "while opening destination for resuming: " + exc.toString(), exc); } innerState.mBytesSoFar = (int) fileLength; if (mInfo.mTotalBytes != -1) { innerState.mHeaderContentLength = Long.toString(mInfo.mTotalBytes); } innerState.mHeaderETag = mInfo.mETag; innerState.mContinuingDownload = true; } } } if (state.mStream != null) { closeDestination(state); } }
Example 4
Source File: DownloadThread.java From Alite with GNU General Public License v3.0 | 4 votes |
/** * Prepare the destination file to receive data. If the file already exists, * we'll set up appropriately for resumption. */ private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { if (state.mFilename != null) { // only true if we've already run a // thread for this download if (!Helpers.isFilenameValid(state.mFilename)) { // this should never happen throw new StopRequest(DownloaderService.STATUS_FILE_ERROR, "found invalid internal destination filename"); } // We're resuming a download that got interrupted File f = new File(state.mFilename); if (f.exists()) { long fileLength = f.length(); if (fileLength == 0) { // The download hadn't actually started, we can restart from // scratch f.delete(); state.mFilename = null; } else if (mInfo.mETag == null) { // This should've been caught upon failure f.delete(); throw new StopRequest(DownloaderService.STATUS_CANNOT_RESUME, "Trying to resume a download that can't be resumed"); } else { // All right, we'll be able to resume this download try { state.mStream = new FileOutputStream(state.mFilename, true); } catch (FileNotFoundException exc) { throw new StopRequest(DownloaderService.STATUS_FILE_ERROR, "while opening destination for resuming: " + exc.toString(), exc); } innerState.mBytesSoFar = (int) fileLength; if (mInfo.mTotalBytes != -1) { innerState.mHeaderContentLength = Long.toString(mInfo.mTotalBytes); } innerState.mHeaderETag = mInfo.mETag; innerState.mContinuingDownload = true; } } } if (state.mStream != null) { closeDestination(state); } }
Example 5
Source File: DownloadThread.java From UnityOBBDownloader with Apache License 2.0 | 4 votes |
/** * Prepare the destination file to receive data. If the file already exists, * we'll set up appropriately for resumption. */ private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { if (state.mFilename != null) { // only true if we've already run a // thread for this download if (!Helpers.isFilenameValid(state.mFilename)) { // this should never happen throw new StopRequest(DownloaderService.STATUS_FILE_ERROR, "found invalid internal destination filename"); } // We're resuming a download that got interrupted File f = new File(state.mFilename); if (f.exists()) { long fileLength = f.length(); if (fileLength == 0) { // The download hadn't actually started, we can restart from // scratch f.delete(); state.mFilename = null; } else if (mInfo.mETag == null) { // This should've been caught upon failure f.delete(); throw new StopRequest(DownloaderService.STATUS_CANNOT_RESUME, "Trying to resume a download that can't be resumed"); } else { // All right, we'll be able to resume this download try { state.mStream = new FileOutputStream(state.mFilename, true); } catch (FileNotFoundException exc) { throw new StopRequest(DownloaderService.STATUS_FILE_ERROR, "while opening destination for resuming: " + exc.toString(), exc); } innerState.mBytesSoFar = (int) fileLength; if (mInfo.mTotalBytes != -1) { innerState.mHeaderContentLength = Long.toString(mInfo.mTotalBytes); } innerState.mHeaderETag = mInfo.mETag; innerState.mContinuingDownload = true; } } } if (state.mStream != null) { closeDestination(state); } }