public static void loadDataFile( BaseActivity context, Locale l, final String sourceUrl, final String dataFileName, final long validPeriod) { Uri fileUri = Uri.parse(dataFileName); String fileName = fileUri.getLastPathSegment(); { File dataFile = new File(getFilesFolder(context, l), fileName); if (dataFile.exists() && (System.currentTimeMillis() - dataFile.lastModified()) < validPeriod) { context.onFileDownloadCompleted(sourceUrl, dataFile.getPath()); } else { Log.i( LOG_TAG, "Data file not found in data dir : " + dataFile.getAbsolutePath() + " Trying to load file..."); FileLoader loader = new FileLoader(context, sourceUrl, dataFile.getAbsolutePath(), l.getLanguage()); loader.loadFileData(); } } }
@Override protected FileLoader doInBackground(Object... arg0) { FileLoader fileLoader = new FileLoader(filename); try { fileLoader.setup(); } catch (Exception e) { err = e; Savelog.e(TAG, "Asyntask rendering unsuccessful." + "\n" + Savelog.getStack(e)); } return fileLoader; }
public FileLoaderResults loadFile(Entity entity, String filename, String loaderAlias) { File file = new File(filename); log.debug("Loading file " + file.getAbsolutePath()); if (!file.isFile() || !file.canRead()) { log.error("Input file is not available."); throw new RuntimeException("Input file " + filename + " is not readable."); } loader = FileLoaderFactory.getFileLoader(Context.getApplicationContext(), loaderAlias); loader.setLoaderAlias(loaderAlias); loader.setEntityLoaderManager(entityLoaderMgr); loader.init(); return loader.parseFile(entity, file); }
@Test public void csslintRules() throws RuleDefinitionException, JsonParseException, JsonMappingException, IOException { FileLoader loader = new JsonFileLoader(getClass().getResourceAsStream("/rules/csslint.json")); loader.load(repository); verify(newRule, times(37)).setName(anyString()); verify(newRule, times(37)).setHtmlDescription(anyString()); verify(newRule, times(1)).setSeverity("MINOR"); verify(newRule, times(2)).setSeverity("MAJOR"); verify(newRule, times(1)).setSeverity("BLOCKER"); verify(newRule, times(1)).setSeverity("CRITICAL"); verify(newRule, times(0)).setStatus(null); }
// once complete, see if ImageView is still around and set up bitmap @Override protected void onPostExecute(FileLoader fileLoader) { super.onPostExecute(fileLoader); if (isCancelled()) { fileLoader = null; } if (hostFragmentReference != null) { final ViewerFragment hostFragment = hostFragmentReference.get(); if (hostFragment != null) { if (fileLoader != null) { hostFragment.mFileLoader = fileLoader; Toast.makeText( hostFragment.getActivity(), "Found " + fileLoader.getNumberOfPages() + " pages", Toast.LENGTH_SHORT) .show(); } else { hostFragment.mFileLoader = null; if (err != null) { Savelog.e(TAG, "Cannot fetch pdf" + "\n" + Savelog.getStack(err)); } Toast.makeText(hostFragment.getActivity(), "Data unavailable", Toast.LENGTH_SHORT) .show(); } // Callback upon finished fetching. hostFragment.onFetchingCompleted(); // Detach host fragment from this task. hostFragment.mFetcherTask = null; } } Savelog.d(TAG, debug, "AsyncTask completed."); }
public void shutdown() { if (loader != null) { loader.shutdown(); } if (entityLoaderMgr != null) { entityLoaderMgr.shutdownConnection(); } Context.shutdown(); }
/** Tests if we can open the file, when it exists. */ @Test public void fileConfirmationWhenFileExists() { stub.setFileName("etc/data/test.txt"); presenter.start(); presenter.fileNameChanged(); presenter.confirmed(); assertTrue(loader.isLoaded()); assertTrue(stub.dataDisplayed()); }
/** Tests if the name of the file changes. */ @Test public void updateFileNameToLoader() { String EXPECTED_FILE = "Stamatis"; stub.setFileName(EXPECTED_FILE); presenter.start(); presenter.fileNameChanged(); assertEquals(EXPECTED_FILE, loader.getFileName()); }
/** Tests if we receive a confirmation when we attempt to open a file that it doesn't exist. */ @Test public void fileConfirmationWhenFileDoesNotExist() { stub.setFileName("RandomName.txt"); presenter.start(); presenter.fileNameChanged(); presenter.confirmed(); assertFalse(loader.isLoaded()); assertEquals(1, stub.getMessagesSent()); }
/** * Tests if we receive a confirmation when we attempt to open a file that it's name is null or an * empty string. */ @Test public void fileConfirmationWhenNameIsNull() { stub.setFileName(null); presenter.start(); presenter.fileNameChanged(); presenter.confirmed(); assertFalse(loader.isLoaded()); assertEquals(1, stub.getMessagesSent()); }
/* package */ static boolean handleLocalFile(String url, LoadListener loadListener, WebSettings settings) { if (URLUtil.isAssetUrl(url)) { FileLoader.requestUrl( url, loadListener, loadListener.getContext(), true, settings.getAllowFileAccess()); return true; } else if (URLUtil.isFileUrl(url)) { FileLoader.requestUrl( url, loadListener, loadListener.getContext(), false, settings.getAllowFileAccess()); return true; } else if (URLUtil.isContentUrl(url)) { // Send the raw url to the ContentLoader because it will do a // permission check and the url has to match.. ContentLoader.requestUrl(loadListener.url(), loadListener, loadListener.getContext()); return true; } else if (URLUtil.isDataUrl(url)) { DataLoader.requestUrl(url, loadListener); return true; } else if (URLUtil.isAboutUrl(url)) { loadListener.data(mAboutBlank.getBytes(), mAboutBlank.length()); loadListener.endData(); return true; } return false; }
public void onFetchingCompleted() { mLoadingView.setVisibility(View.GONE); mListView.setVisibility(View.VISIBLE); mListView.setAlpha(1f); if (mFileLoader != null) { Savelog.d(TAG, debug, "bitmap page length = " + mFileLoader.getNumberOfPages()); if (mBitmapListAdapter == null) { // Don't reset adapter if already exists mBitmapListAdapter = new BitmapListAdapter(this, mFileLoader.getPageNames()); } mListView.setAdapter(mBitmapListAdapter); mListView.setRecyclerListener( new RecyclerListener() { @Override public void onMovedToScrapHeap(View view) { final ImageView imageView = (ImageView) view.findViewById(R.id.listItem_bitmap_id); Savelog.d(TAG, debug, "Called recycler."); imageView.setImageBitmap(null); imageView.setTag(null); } }); } }
private void addDatalogData() { StringBuilder sb = new StringBuilder(); List<Record> records = FileLoader.getAllSTDFRecordsOfType("DTR"); for (Record record : records) { try { Object textObj = record.getData().getField("TEXT_DAT"); sb.append(textObj == null ? "" : textObj.toString()).append("\n"); } catch (Exception e) { // ignore } } textArea.setText(sb.toString()); }
@Override protected Bitmap doInBackground(Object... params) { Bitmap bitmap = null; key = (String) params[0]; int position = (Integer) params[1]; Savelog.d(TAG, debug, "AsyncTask trying to load bitmap from cache"); if (fileLoader == null) { Savelog.e(TAG, "file loader is null."); } else { int pageNumberNeeded = position + 1; bitmap = fileLoader.load(appContext, maxWidth, pageNumberNeeded, pageRange); } // bitmap could be null if oom error or cache flushed out. return bitmap; }
public static void main(String[] args) { File backFile = new File(ROOT_DIR + "2012-05-16b/raw_data/"); for (String fileName : backFile.list()) { // File sourceFile = new File(backFile + fileName); String mergedFileName = ROOT_DIR + "2012-05-16/raw_data/" + fileName; // File mergedFile = new File(mergedFileName); FileWriter fstream; try { fstream = new FileWriter(mergedFileName, true); BufferedWriter out = new BufferedWriter(fstream); String srcContent = FileLoader.loadFile(ROOT_DIR + "2012-05-16b/raw_data/" + fileName); out.write(srcContent); out.close(); } catch (IOException e) { e.printStackTrace(); } } }