List of usage examples for com.google.common.io Resources toByteArray
public static byte[] toByteArray(URL url) throws IOException
From source file:org.apache.drill.exec.compile.bytecode.ReplaceMethodInvoke.java
public static void main(String[] args) throws Exception { final String k2 = "org/apache/drill/Pickle.class"; final URL url = Resources.getResource(k2); final byte[] clazz = Resources.toByteArray(url); final ClassReader cr = new ClassReader(clazz); final ClassWriter cw = writer(); final TraceClassVisitor visitor = new TraceClassVisitor(cw, new Textifier(), new PrintWriter(System.out)); final ValueHolderReplacementVisitor v2 = new ValueHolderReplacementVisitor(visitor, true); cr.accept(v2, ClassReader.EXPAND_FRAMES);//| ClassReader.SKIP_DEBUG); final byte[] output = cw.toByteArray(); Files.write(output, new File("/src/scratch/bytes/S.class")); check(output);/* w w w .j a v a 2 s . c om*/ final DrillConfig c = DrillConfig.forClient(); final SystemOptionManager m = new SystemOptionManager(c, new LocalPStoreProvider(c)); m.init(); try (QueryClassLoader ql = new QueryClassLoader(DrillConfig.create(), m)) { ql.injectByteCode("org.apache.drill.Pickle$OutgoingBatch", output); Class<?> clz = ql.loadClass("org.apache.drill.Pickle$OutgoingBatch"); clz.getMethod("x").invoke(null); } }
From source file:org.whispersystems.bithub.util.Badge.java
public static byte[] createFor(String price) throws IOException { byte[] badgeBackground = Resources.toByteArray(Resources.getResource("assets/badge.png")); BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(badgeBackground)); Graphics2D graphics = bufferedImage.createGraphics(); graphics.setFont(new Font("OpenSans", Font.PLAIN, 34)); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); graphics.drawString(price + " USD", 86, 45); graphics.dispose();// ww w .jav a2 s . c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, "png", baos); return baos.toByteArray(); }
From source file:com.google.appinventor.server.util.ResourceUtil.java
/** * Returns a byte array containing the binary content of the signed * codeblocks jar.//from ww w .j a v a2 s .c o m */ public static byte[] downloadSignedCodeblocksJar() throws IOException { // The codeblocks jar was signed at build time. // We expect the jar file to be in our class directory URL url = ResourceUtil.class.getResource(CODEBLOCKS_JAR); return Resources.toByteArray(url); }
From source file:org.dishevelled.bio.benchmarks.Utils.java
/** * Copy a classpath resource to a file./*w ww. j a va 2 s . co m*/ * * @param name classpath resource name * @param file file to copy classpath resource to * @throws IOException if an I/O error occurs */ static void copyResource(final String name, final File file) throws IOException { Files.write(Resources.toByteArray(Utils.class.getResource(name)), file); }
From source file:com.google.errorprone.bugpatterns.apidiff.Java7ApiChecker.java
private static ApiDiff loadApiDiff() { try {//w w w . j a v a 2 s .c om ApiDiffProto.Diff.Builder diffBuilder = ApiDiffProto.Diff.newBuilder(); byte[] diffData = Resources .toByteArray(Resources.getResource(Java7ApiChecker.class, "7to8diff.binarypb")); diffBuilder.mergeFrom(diffData) .addClassDiff(ApiDiffProto.ClassDiff.newBuilder() .setMemberDiff(ApiDiffProto.MemberDiff.newBuilder() .setClassName("com/google/common/base/Predicate") .addMember(ApiDiffProto.ClassMember.newBuilder().setIdentifier("test") .setMemberDescriptor("(Ljava/lang/Object;)Z")))) .addClassDiff(ApiDiffProto.ClassDiff.newBuilder() .setMemberDiff(ApiDiffProto.MemberDiff.newBuilder() .setClassName("com/google/common/base/BinaryPredicate") .addMember(ApiDiffProto.ClassMember.newBuilder().setIdentifier("test") .setMemberDescriptor("(Ljava/lang/Object;Ljava/lang/Object;)Z")))); return ApiDiff.fromProto(diffBuilder.build()); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.google.appinventor.server.util.ResourceUtil.java
/** * Returns a byte array containing the binary content of the starter app apk. *///from w w w. j a v a 2 s . c o m public static byte[] downloadStarterAppApk() throws IOException { // We expect the start app apk file to be in our class directory return Resources.toByteArray(ResourceUtil.class.getResource(STARTER_APP_APK)); }
From source file:org.whispersystems.bithub.util.Badge.java
public static byte[] createSmallFor(String price) throws IOException { byte[] badgeBackground = Resources.toByteArray(Resources.getResource("assets/badge-small.png")); BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(badgeBackground)); Graphics2D graphics = bufferedImage.createGraphics(); graphics.setFont(new Font("OpenSans", Font.PLAIN, 9)); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); graphics.drawString(price + " USD", 22, 14); graphics.dispose();/*from w ww .j av a 2s . com*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, "png", baos); return baos.toByteArray(); }
From source file:eu.redzoo.article.planetcassandra.reactive.service.PictureService.java
@Path("/{id}") @GET/*ww w.ja v a 2s. c o m*/ @Produces("image/png") public byte[] getHotelThumbnail() throws IOException { return Resources.toByteArray(Resources.getResource("hotel.png")); }
From source file:ch.ledcom.demo.redirect.ImageServlet.java
private InputStream loadImage() throws IOException { if (imageBytes == null) { imageBytes = Resources.toByteArray(getClass().getClassLoader().getResource("test.png")); }/*from ww w . j av a 2 s . co m*/ return new ByteArrayInputStream(imageBytes); }
From source file:org.activityinfo.server.report.renderer.ppt.PPTTileHandler.java
@Override public void addTile(String tileUrl, int x, int y, int width, int height) { try {//from w ww. j a v a2 s . c om byte[] imageBytes = Resources.toByteArray(new URL(tileUrl)); int pictureIndex = ppt.addPicture(imageBytes, Picture.PNG); Picture basemap = new Picture(pictureIndex); basemap.setAnchor(new Rectangle(x, y, width, height)); basemap.setLineWidth(0); shapeGroup.addShape(basemap); } catch (MalformedURLException e) { throw new RuntimeException("Bad tile URL", e); } catch (IOException e) { // ignore missing tiles } }