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.speed.ob.api.ClassStore.java
public void init(JarInputStream jarIn, File output, File in) throws IOException { ZipEntry entry;/*from www.ja va 2 s . co m*/ JarOutputStream out = new JarOutputStream(new FileOutputStream(new File(output, in.getName()))); while ((entry = jarIn.getNextEntry()) != null) { byte[] data = IOUtils.toByteArray(jarIn); if (entry.getName().endsWith(".class")) { ClassReader reader = new ClassReader(data); ClassNode cn = new ClassNode(); reader.accept(cn, ClassReader.EXPAND_FRAMES); store.put(cn.name, cn); } else if (!entry.isDirectory()) { Logger.getLogger(getClass().getName()).finer("Storing " + entry.getName() + " in output file"); JarEntry je = new JarEntry(entry.getName()); out.putNextEntry(je); out.write(data); out.closeEntry(); } } out.close(); }
From source file:cpcc.core.utils.PngImageStreamResponseTest.java
@Test public void shouldCreateDefaultPngStreamResponse() throws IOException { byte[] expected = PngImageStreamResponse.ONE_PIXEL_EMPTY_PNG; PngImageStreamResponse response = new PngImageStreamResponse(); assertThat(response.getStream()).isNotNull(); byte[] actual = IOUtils.toByteArray(response.getStream()); assertThat(actual).isEqualTo(expected); assertThat(response.getStream().read()).isEqualTo(-1); }
From source file:com.woodcomputing.bobbin.format.JEFFormat.java
@Override public Design load(File file) { byte[] bytes = null; try (InputStream is = new FileInputStream(file)) { bytes = IOUtils.toByteArray(is); } catch (IOException ex) { log.catching(ex);//from ww w.ja v a2 s .c o m } ByteBuffer bb = ByteBuffer.wrap(bytes); bb.order(ByteOrder.LITTLE_ENDIAN); JEF jef = new JEF(); jef.setFirstStitchLocation(bb.getInt(0)); log.debug("First Stitch Location: {}", jef.getFirstStitchLocation()); jef.setThreadChangeCount(bb.getInt(24)); log.debug("Threads Changes: {}", jef.getThreadChangeCount()); jef.setHoop(Hoop.id2Hoop(bb.getInt(32))); log.debug("Hoop: {}", jef.getHoop()); jef.setStitchCount(bb.getInt(28)); log.debug("Stitch Count: {}", jef.getStitchCount()); bb.position(116); JEFColor[] colors = new JEFColor[jef.getThreadChangeCount()]; for (int i = 0; i < jef.getThreadChangeCount(); i++) { colors[i] = jefColorMap.get(bb.getInt()); } jef.setThreadColors(colors); for (int i = 0; i < jef.getThreadChangeCount(); i++) { log.debug("ThreadType{}: {}", i, bb.getInt()); } int dx = 0; int dy = 0; int cx = 0; int cy = 0; int nx = 0; int ny = 0; int change = 1; int stitches = 0; boolean isMove = false; bb.position(jef.getFirstStitchLocation()); JEFColor color = jef.getThreadColors()[change - 1]; Design design = new Design(); StitchGroup stitchGroup = new StitchGroup(); stitchGroup.setColor(color.getRgb()); for (int stitch = 1; stitch < jef.getStitchCount(); stitch++) { dx = bb.get(); dy = bb.get(); if (dx == -128) { switch (dy) { case 1: log.debug("change: {}", bb.position()); change++; color = jef.getThreadColors()[change - 1]; design.getStitchGroups().add(stitchGroup); stitchGroup = new StitchGroup(); stitchGroup.setColor(color.getRgb()); // bb.get(); // bb.get(); continue; case 2: // log.debug("move"); isMove = true; break; case 16: log.debug("last"); isMove = true; break; } } else { nx = cx + dx; ny = cy + dy; if (isMove) { isMove = false; } // } else { // log.debug("stitch"); stitches++; Stitch designStitch = new Stitch(cx, -cy, nx, -ny); stitchGroup.getStitches().add(designStitch); // } cx = nx; cy = ny; } } log.debug("Changes: {} Stitches {} End: {}", change, stitches, bb.position()); return design; }
From source file:com.jayway.restassured.itest.java.presentation.MultiPartITest.java
@Test public void byteArrayUploading() throws Exception { // Given//from w w w . j av a 2s . co m final byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream("/car-records.xsd")); // When given().multiPart("file", "myFile", bytes).expect().statusCode(200).body(is(new String(bytes))).when() .post("/multipart/file"); }
From source file:com.gargoylesoftware.htmlunit.html.applets.AppletClassLoader.java
/** * Adds the class defined by the WebResponse to the classpath for the applet. * @param className the name of the class to load * @param webResponse the web response/* w ww. java 2 s . c om*/ * @throws IOException in case of problem working with the response content */ public void addClassToClassPath(final String className, final WebResponse webResponse) throws IOException { final byte[] bytes = IOUtils.toByteArray(webResponse.getContentAsStream()); defineClass(className, bytes, 0, bytes.length); }
From source file:com.grapeshot.halfnes.FileUtils.java
public static int[] readfromfile(final InputStream inputStream) { try {// w ww . j av a2s . c o m byte[] bytes = IOUtils.toByteArray(inputStream); int[] ints = new int[bytes.length]; for (int i = 0; i < bytes.length; i++) { ints[i] = (short) (bytes[i] & 0xFF); } return ints; } catch (IOException e) { throw new Error(); } }
From source file:com.jayway.restassured.itest.java.NonMultiPartUploadITest.java
@Test public void uploadingWorksForByteArraysWithPut() throws Exception { // Given//from w ww .ja va 2 s.co m final byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream("/car-records.xsd")); // When given().content(bytes).when().put("/file").then().statusCode(200).body(is(new String(bytes))); }
From source file:com.mytube.MyTubeWS.java
public String download() throws FileNotFoundException, IOException { return Base64.encode(IOUtils.toByteArray(f)); }
From source file:applica.framework.licensing.LicenseManager.java
public void validate() throws InvalidLicenseException { Objects.requireNonNull(user); InputStream in = getClass().getResourceAsStream("/".concat(LICENSE_FILE)); if (in == null) { throw new LicenseException(LICENSE_FILE + " not found"); }/*from ww w.j a va 2 s . c o m*/ try { byte[] bytes = IOUtils.toByteArray(in); License license = new License(user, bytes); license.validate(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(in); } }
From source file:cpcc.core.utils.GeoJsonStreamResponseTest.java
@Test public void shouldReturnFeatureCollectionAsJsonStream() throws IOException { FeatureCollection featureCollection = new FeatureCollection(); byte[] expected = new ObjectMapper().disable(SerializationFeature.INDENT_OUTPUT) .writeValueAsBytes(featureCollection); GeoJsonStreamResponse sut = new GeoJsonStreamResponse(featureCollection); byte[] actual = IOUtils.toByteArray(sut.getStream()); assertThat(sut.getContentType()).isEqualTo("application/json"); assertThat(actual).isEqualTo(expected); }