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:be.roots.taconic.pricingguide.util.HttpUtil.java
public static byte[] readByteArray(String urlAsString, String userName, String password) { try {//from www . ja v a2 s . co m final HttpURLConnection con = getInputStreamFor(urlAsString, userName, password); final BufferedInputStream in = new BufferedInputStream(con.getInputStream()); final byte[] response = IOUtils.toByteArray(in); IOUtils.closeQuietly(in); return response; } catch (IOException e) { LOGGER.error(e.getLocalizedMessage(), e); } return null; }
From source file:com.collective.celos.ci.testing.fixtures.convert.AvroToJsonConverter.java
@Override public FixFile convert(TestRun testRun, FixFile ff) throws IOException { byte[] bytes = IOUtils.toByteArray(ff.getContent()); if (bytes.length == 0) { return ff; }/*w w w. j ava 2s .com*/ ByteArrayOutputStream os = new ByteArrayOutputStream(); GenericDatumReader<Object> reader = new GenericDatumReader<>(); FileReader<Object> fileReader = DataFileReader.openReader(new SeekableByteArrayInput(bytes), reader); try { Schema schema = fileReader.getSchema(); DatumWriter<Object> writer = new GenericDatumWriter<>(schema); JsonEncoder encoder = EncoderFactory.get().jsonEncoder(schema, os); for (Object datum : fileReader) { writer.write(datum, encoder); } encoder.flush(); } finally { fileReader.close(); } return new FixFile(new ByteArrayInputStream(os.toByteArray())); }
From source file:com.triage.bytecodemaster.CachingGroovyClassLoader.java
public byte[] getClassBytes(String name) throws IOException { return IOUtils.toByteArray(getResourceAsStream(name)); }
From source file:com.ctriposs.r2.filter.compression.SnappyCompressor.java
@Override public byte[] deflate(InputStream data) throws CompressionException { try {/*from w w w. j a v a 2 s . c om*/ byte[] temp = IOUtils.toByteArray(data); return Snappy.compress(temp); } catch (IOException e) { throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName(), e); } }
From source file:edu.jhu.hlt.concrete.stanford.AnnotatedNYTTest.java
@Before public void setUp() throws Exception { try (InputStream is = Files.newInputStream(p); BufferedInputStream bin = new BufferedInputStream(is, 1024 * 8 * 16);) { byte[] nytdocbytes = IOUtils.toByteArray(bin); this.nytComm = new CommunicationizableAnnotatedNYTDocument( new AnnotatedNYTDocument(parser.fromByteArray(nytdocbytes, false))).toCommunication(); }/* w w w . j a v a 2s .c o m*/ }
From source file:managedBean.InsertarCiudadBean.java
public String doInsertarCiudad() { try {/*from w w w. j av a 2 s.com*/ InputStream inputStream = imagePart.getInputStream(); ciudad.setFoto(IOUtils.toByteArray(inputStream)); } catch (IOException ex) { Logger.getLogger(InsertarCiudadBean.class.getName()).log(Level.SEVERE, null, ex); } ciudadFacade.create(ciudad); ciudadBean.ciudad = ciudad; ciudad = new Ciudad(); return ""; }
From source file:com.t3.image.ImageUtil.java
/** * Load the image. Does not create a graphics configuration compatible version. *//*from ww w. ja v a 2 s . c o m*/ public static Image getImage(File file) throws IOException { try (FileInputStream is = new FileInputStream(file)) { return bytesToImage(IOUtils.toByteArray(is)); } }
From source file:com.cloudera.csd.validation.SdlTestUtils.java
public static ServiceDescriptor parseSDL(String path) { try {/*from w w w. ja v a 2 s . com*/ InputStream stream = SdlTestUtils.class.getResourceAsStream(path); return SDL_PARSER.parse(IOUtils.toByteArray(stream)); } catch (IOException io) { throw new RuntimeException(io); } }
From source file:io.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx.java
@Override public ServletInputStream getInputStream() throws IOException { if (this.inputStream == null) { if (cacheRequest) { byte inputBytes[] = IOUtils.toByteArray(getRequest().getInputStream()); ByteBuf byteBuf = Unpooled.wrappedBuffer(inputBytes); this.inputStream = new BufferInputStream(byteBuf); setBodyBuffer(Buffer.buffer(Unpooled.wrappedBuffer(byteBuf))); } else {// w w w. java 2 s .c o m this.inputStream = getRequest().getInputStream(); } } return this.inputStream; }
From source file:net.nicholaswilliams.java.licensing.mock.MockFilePrivateKeyDataProvider.java
/** * This method returns the data from the file containing the encrypted * private key from the public/private key pair. The contract for this * method can be fulfilled by storing the data in a byte array literal * in the source code itself.//from w w w . j ava 2 s. com * * @return the encrypted file contents from the private key file. * @throws net.nicholaswilliams.java.licensing.exception.KeyNotFoundException if the key data could not be retrieved; an acceptable message or chained cause must be provided. */ public byte[] getEncryptedPrivateKeyData() throws KeyNotFoundException { try { return IOUtils.toByteArray(this.getClass().getResourceAsStream("mock.private.key")); } catch (IOException e) { throw new KeyNotFoundException("The private key file was not found.", e); } }