List of usage examples for com.google.common.io InputSupplier InputSupplier
InputSupplier
From source file:org.jasig.portal.io.xml.JaxbPortalDataHandlerService.java
/** * Extracts the archive resource and then runs the batch-import process on it. *///from ww w . j a v a 2s .c om protected void importDataArchive(final Resource resource, final ArchiveInputStream resourceStream, BatchImportOptions options) { final File tempDir = Files.createTempDir(); try { ArchiveEntry archiveEntry; while ((archiveEntry = resourceStream.getNextEntry()) != null) { final File entryFile = new File(tempDir, archiveEntry.getName()); if (archiveEntry.isDirectory()) { entryFile.mkdirs(); } else { entryFile.getParentFile().mkdirs(); Files.copy(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return new CloseShieldInputStream(resourceStream); } }, entryFile); } } importData(tempDir, null, options); } catch (IOException e) { throw new RuntimeException( "Failed to extract data from '" + resource + "' to '" + tempDir + "' for batch import.", e); } finally { FileUtils.deleteQuietly(tempDir); } }
From source file:org.apereo.portal.io.xml.JaxbPortalDataHandlerService.java
/** * Extracts the archive resource and then runs the batch-import process on it. *//*from www .j av a2 s. co m*/ protected void importDataArchive(final Resource resource, final ArchiveInputStream resourceStream, BatchImportOptions options) { final File tempDir = Files.createTempDir(); try { ArchiveEntry archiveEntry; while ((archiveEntry = resourceStream.getNextEntry()) != null) { final File entryFile = new File(tempDir, archiveEntry.getName()); if (archiveEntry.isDirectory()) { entryFile.mkdirs(); } else { entryFile.getParentFile().mkdirs(); Files.copy(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return new CloseShieldInputStream(resourceStream); } }, entryFile); } } importDataDirectory(tempDir, null, options); } catch (IOException e) { throw new RuntimeException( "Failed to extract data from '" + resource + "' to '" + tempDir + "' for batch import.", e); } finally { FileUtils.deleteQuietly(tempDir); } }
From source file:com.xebialabs.overthere.OverthereConnectionItestBase.java
@Test public void shouldTruncateExistingTargetFileOnCopy() throws Exception { final OverthereFile existingDestination = connection.getTempFile("existing"); writeData(existingDestination, "**********\n**********\n**********\n**********\n**********\n".getBytes()); final OverthereFile newSource = connection.getTempFile("newContents"); writeData(newSource, "++++++++++".getBytes()); newSource.copyTo(existingDestination); ByteArrayOutputStream to = new ByteArrayOutputStream(); ByteStreams.copy(new InputSupplier<InputStream>() { @Override//from www .jav a 2 s . c o m public InputStream getInput() throws IOException { return existingDestination.getInputStream(); } }, to); byte[] bytes = to.toByteArray(); assertThat(bytes.length, equalTo(10)); assertThat(bytes, equalTo("++++++++++".getBytes())); }
From source file:com.entradahealth.entrada.android.app.personal.activities.job_list.JobListActivity.java
private void showLicensing() { LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.license_dialog, null); TextView textview = (TextView) view.findViewById(R.id.license_text); InputStream is = getResources().openRawResource(R.raw.licenses); try {/* w ww.j a va2s . c om*/ textview.setText(CharStreams.toString(new InputSupplier<InputStreamReader>() { public InputStreamReader getInput() throws IOException { return new InputStreamReader(getResources().openRawResource(R.raw.licenses)); } })); } catch (IOException ex) { Toast.makeText(this, "Sorry, error displaying licenses. Contact support for license details.", Toast.LENGTH_SHORT); } AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setTitle("License Information"); // alertDialog.setMessage("Here is a really long message."); alertDialog.setView(view); AlertDialog alert = alertDialog.create(); alert.show(); }
From source file:co.cask.cdap.gateway.handlers.AppFabricHttpHandler.java
@Nullable private SessionInfo retrieve(String accountId) { try {//from w ww.jav a 2 s . c o m final Location outputDir = locationFactory.create(archiveDir + "/" + accountId); if (!outputDir.exists()) { return null; } final Location sessionInfoFile = outputDir.append("session.json"); InputSupplier<Reader> reader = new InputSupplier<Reader>() { @Override public Reader getInput() throws IOException { return new InputStreamReader(sessionInfoFile.getInputStream(), "UTF-8"); } }; Gson gson = new GsonBuilder().registerTypeAdapter(Location.class, new LocationCodec(locationFactory)) .create(); Reader r = reader.getInput(); try { return gson.fromJson(r, SessionInfo.class); } finally { Closeables.closeQuietly(r); } } catch (IOException e) { LOG.warn("Failed to retrieve session info for account."); } return null; }