List of usage examples for org.apache.commons.io IOUtils toByteArray
public static byte[] toByteArray(String input) throws IOException
String
as a byte[]
using the default character encoding of the platform. From source file:com.shuzhilian.icu.license.LicenseViewer.java
private void startUp(File key, char[] keyPasswd, char[] licensePasswd) { LicenseManagerProperties.setPublicKeyDataProvider(() -> { try {/* w w w.j a v a 2 s . c o m*/ return IOUtils.toByteArray(new FileInputStream(key)); } catch (IOException e) { throw new KeyNotFoundException("Read key data failed.", e); } }); LicenseManagerProperties.setPublicKeyPasswordProvider(() -> keyPasswd); LicenseManagerProperties.setLicenseProvider((context) -> new FileLicenseProvider().getLicense(context)); LicenseManagerProperties.setLicensePasswordProvider(() -> licensePasswd); LicenseManagerProperties.setLicenseValidator(license -> { }); LicenseManagerProperties.setCacheTimeInMinutes(5); LicenseManager.getInstance(); }
From source file:com.google.mr4c.util.ByteBufferInputStreamTest.java
@Test public void testReadFully() throws Exception { byte[] data = new byte[] { -45, 76, 93, -112, 0 }; ByteBuffer buf = ByteBuffer.wrap(data); ByteBufferInputStream stream = new ByteBufferInputStream(buf); byte[] result = IOUtils.toByteArray(stream); stream.close();/* w w w. ja v a 2 s.co m*/ assertTrue(Arrays.equals(data, result)); }
From source file:com.googlecode.arit.icon.variant.DefaultIconVariant.java
public ImageData createIconImage(IconProvider iconProvider) { try {/*from ww w . ja va2 s. co m*/ InputStream in = iconProvider.getIconContent(); try { return new ImageData(iconProvider.getIconFormat(), IOUtils.toByteArray(in)); } finally { in.close(); } } catch (IOException ex) { throw new IconException(ex); } }
From source file:com.yahoo.gondola.container.impl.ZookeeperConfigProviderTest.java
@BeforeMethod public void setUp() throws Exception { if (server == null) { server = new ZookeeperServer(); server.getClient().create().creatingParentContainersIfNeeded() .forPath(ZookeeperUtils.configPath(SERVICE_NAME), IOUtils.toByteArray(file)); }//w w w. ja v a 2 s . c o m configProvider = new ZookeeperConfigProvider(server.getClient(), SERVICE_NAME); }
From source file:com.canoo.webtest.util.FileUtil.java
/** * Reads a file into a byte[].//from w ww. ja v a 2 s . c o m * * @param file * @param step * @return the resulting byte[] */ public static byte[] readFileToByteArray(final File file, final Step step) { String canonicalPath = null; byte[] result = null; InputStream inputStream = null; try { canonicalPath = file.getCanonicalPath(); inputStream = new FileInputStream(file); result = IOUtils.toByteArray(inputStream); } catch (IOException e) { throw new StepExecutionException("Could not find/read \"" + canonicalPath + "\".", step); } finally { IOUtils.closeQuietly(inputStream); } return result; }
From source file:br.on.daed.services.pdf.DadosMagneticos.java
public static byte[] gerarPDF(String ano, String tipo) throws IOException, InterruptedException, UnsupportedOperationException { File tmpFolder;/* ww w.j a v a 2 s .co m*/ String folderName; Double anoDouble = Double.parseDouble(ano); List<String> dados = Arrays.asList(TIPO_DADOS_MAGNETICOS); byte[] ret = null; if (anoDouble >= ANO_MAGNETICO[0] && anoDouble < ANO_MAGNETICO[1] && dados.contains(tipo)) { do { folderName = "/tmp/dislin" + Double.toString(System.currentTimeMillis() * Math.random()); tmpFolder = new File(folderName); } while (tmpFolder.exists()); tmpFolder.mkdir(); ProcessBuilder processBuilder = new ProcessBuilder("/opt/declinacao-magnetica/./gerar", ano, tipo); processBuilder.directory(tmpFolder); processBuilder.environment().put("LD_LIBRARY_PATH", "/usr/local/dislin"); Process proc = processBuilder.start(); proc.waitFor(); ProcessHelper.outputProcess(proc); File arquivoServido = new File(folderName + "/dislin.pdf"); FileInputStream fis = new FileInputStream(arquivoServido); ret = IOUtils.toByteArray(fis); processBuilder = new ProcessBuilder("rm", "-r", folderName); tmpFolder = new File("/"); processBuilder.directory(tmpFolder); Process delete = processBuilder.start(); delete.waitFor(); } else { throw new UnsupportedOperationException("Entrada invlida"); } return ret; }
From source file:com.twcable.jackalope.impl.jcr.BinaryImpl.java
public BinaryImpl(InputStream stream) { byte[] b = new byte[0]; try {/*w ww . j a v a 2s . com*/ b = IOUtils.toByteArray(stream); } catch (IOException ioe) { /* ignore */ } bytes = b; }
From source file:com.opensymphony.webwork.util.classloader.stores.FileResourceStore.java
public byte[] read(final String resourceName) { InputStream is = null;/* w w w .ja v a 2s . c o m*/ try { is = new FileInputStream(getFile(resourceName)); final byte[] data = IOUtils.toByteArray(is); return data; } catch (FileNotFoundException e) { } catch (IOException e) { } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } return null; }
From source file:de.weltraumschaf.registermachine.bytecode.ByteCodeReader.java
/** * Read all bytes as array.//from ww w. ja va 2 s . c om * * @return byte code as array of bytes * @throws IOException if, I/O errors happened */ public byte[] read() throws IOException { return IOUtils.toByteArray(input); }
From source file:com.eatnumber1.util.compression.AbstractCompressionProvider.java
@NotNull @Override/*from www.jav a 2s . co m*/ public byte[] compress(@NotNull byte[] data) throws CompressionException { InputStream compressedData = compress(new ByteArrayInputStream(data)); try { return IOUtils.toByteArray(compressedData); } catch (IOException e) { throw new CompressionException(e); } }