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.wisemapping.rest.DebugMappingJacksonHttpMessageConverter.java
@Override protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, JsonHttpMessageNotReadableException { try {/*w w w . ja v a 2 s . c om*/ final byte[] bytes = IOUtils.toByteArray(inputMessage.getBody()); final ByteArrayInputStream bais = new ByteArrayInputStream(bytes); final WrapHttpInputMessage wrap = new WrapHttpInputMessage(bais, inputMessage.getHeaders()); return super.readInternal(clazz, wrap); } catch (org.springframework.http.converter.HttpMessageNotReadableException e) { throw new JsonHttpMessageNotReadableException("Request Body could not be read", e); } catch (IOException e) { throw new JsonHttpMessageNotReadableException("Request Body could not be read", e); } }
From source file:com.imag.nespros.network.devices.UtilityDevice.java
public UtilityDevice(String name, double cpuSpeed, int totalMemory) { super(name, cpuSpeed, totalMemory, DeviceType.UTILITY); //icon= new MyLayeredIcon(new ImageIcon("icons"+File.separator+"utility.jpg").getImage()); try {//www . jav a 2 s .c o m byte[] imageInByte; imageInByte = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("image/utility.jpg")); icon = new MyLayeredIcon(new ImageIcon(imageInByte).getImage()); } catch (IOException ex) { Logger.getLogger(AMIDevice.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.chboeh.lightspeed.demo.util.ShuffleTest.java
@Before public void setUp() { try {//from ww w . ja v a 2 s.c o m //question.json file data is a project resource InputStream is = QuizDemo.class.getResourceAsStream("/questions.json"); byte[] jsonData = IOUtils.toByteArray(is); ObjectMapper objectMapper = new ObjectMapper(); //convert json string to object Root root = objectMapper.readValue(jsonData, Root.class); Quiz quiz = root.getQuiz(); questions = new ArrayList(quiz.getQuestions().size()); for (Map<String, Object> item : quiz.getQuestions()) { //Parse questions and set the correct answer option Question question = objectMapper.convertValue(item, Question.class); question.setCorrectAnswer(); questions.add(question); } } catch (IOException ex) { System.out.println(ex); } }
From source file:com.hurence.logisland.processor.excel.ExcelExtractTest.java
private byte[] resolveClassPathResource(String name) throws IOException { try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(name)) { return IOUtils.toByteArray(is); }//from ww w .j a v a 2 s . co m }
From source file:gov.usgs.cida.iplover.util.ImageStorage.java
public static byte[] get(String uuid) throws IOException { AmazonS3 s3 = prepS3Client();// w w w . j a v a2 s. c om String imageKey = KEY_BASE + "/" + uuid + ".jpg"; S3Object object = s3.getObject(new GetObjectRequest(BUCKET_NAME, imageKey)); return IOUtils.toByteArray(object.getObjectContent()); }
From source file:net.darkmist.alib.io.Slurp.java
public static byte[] slurp(DataInput din) throws IOException { ByteArrayOutputStream baos;/*from w w w. j av a2 s. c om*/ int b; if (din instanceof InputStream) return IOUtils.toByteArray((InputStream) din); baos = new ByteArrayOutputStream(); while (true) { try { b = din.readByte(); } catch (EOFException e) { return baos.toByteArray(); } baos.write(b); } }
From source file:com.edmunds.etm.common.xml.TestDataProvider.java
public static byte[] loadConfigurationFromFile(String fileName) { InputStream stream = TestDataProvider.class.getResourceAsStream(fileName); try {//from ww w .j av a2s. c o m return IOUtils.toByteArray(stream); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.seer.datacruncher.streams.ExcelStreamTest.java
@Test public void testExcelStream() { String fileName = properties.getProperty("excel_test_stream_file_name"); InputStream in = this.getClass().getClassLoader().getResourceAsStream(stream_file_path + fileName); byte[] arr = null; try {//from w w w . j ava2 s . c o m arr = IOUtils.toByteArray(in); } catch (IOException e) { assertTrue("IOException while excel test file reading", false); } DatastreamsInput datastreamsInput = new DatastreamsInput(); datastreamsInput.setUploadedFileName(fileName); String res = datastreamsInput.datastreamsInput(null, (Long) schemaEntity.getIdSchema(), arr, true); assertTrue("Excel file validation failed", Boolean.parseBoolean(res)); }
From source file:com.receipts.services.ReceiptsImageService.java
public ByteArrayInputStream getReceiptsImage(int id) { ByteArrayInputStream bais = null; String sql = "SELECT RECEIPT_IMG FROM RECEIPTS WHERE ID = ?"; try (Connection conn = DbUtils.getDbConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setInt(1, id);//from www. j ava 2 s. c om try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { Blob imgBlob = rs.getBlob("RECEIPT_IMG"); InputStream is = imgBlob.getBinaryStream(); bais = new ByteArrayInputStream(IOUtils.toByteArray(is)); } } } catch (IOException | SQLException ex) { ex.printStackTrace(); } return bais; }
From source file:com.jayway.restassured.itest.java.NonMultiPartUploadITest.java
@Test public void uploadingWorksForByteArraysWithPost() throws Exception { // Given/* w w w . j av a 2 s .com*/ final byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream("/car-records.xsd")); // When given().contentType(ContentType.BINARY).content(bytes).when().post("/file").then().statusCode(200) .body(is(new String(bytes))); }