List of usage examples for com.google.common.io Resources toByteArray
public static byte[] toByteArray(URL url) throws IOException
From source file:services.docx.DisposicionServiceDocx.java
@PostConstruct public void init() throws IOException, LoadTemplateException { final byte[] bytes = Resources.toByteArray(Resources.getResource(this.getClass(), "disposicion.docx")); wordprocessingMLPackage = docxService.loadPackage(new ByteArrayInputStream(bytes)); }
From source file:services.docx.ResolucionServiceDocx.java
@PostConstruct public void init() throws IOException, LoadTemplateException { final byte[] bytes = Resources.toByteArray(Resources.getResource(this.getClass(), "resolucion.docx")); wordprocessingMLPackage = docxService.loadPackage(new ByteArrayInputStream(bytes)); }
From source file:services.docx.ExpedienteServiceDocx.java
@PostConstruct public void init() throws IOException, LoadTemplateException { final byte[] bytes = Resources.toByteArray(Resources.getResource(this.getClass(), "expediente.docx")); wordprocessingMLPackage = docxService.loadPackage(new ByteArrayInputStream(bytes)); }
From source file:org.graylog2.shared.rest.resources.documentation.DocumentationBrowserResource.java
@GET @Path("/{route: .*}") public Response asset(@PathParam("route") String route) { // Directory traversal should not be possible but just to make sure.. if (route.contains("..")) { throw new BadRequestException("Not allowed to access parent directory"); }/*from w w w.j a v a2 s.c o m*/ if (route.trim().equals("")) { route = "index.html"; } final URL resource = classLoader.getResource("swagger/" + route); if (null != resource) { try { final byte[] resourceBytes = Resources.toByteArray(resource); return Response.ok(resourceBytes, mimeTypes.getContentType(route)) .header("Content-Length", resourceBytes.length).build(); } catch (IOException e) { throw new NotFoundException("Couldn't load " + resource, e); } } else { throw new NotFoundException("Couldn't find " + route); } }
From source file:eu.redzoo.article.planetcassandra.reactive.service.completable.HotelService.java
public HotelService(Dao hotelsDao) throws IOException { this.hotelsDao = hotelsDao; defaultPicture = Resources.toByteArray(Resources.getResource("error.jpg")); }
From source file:org.apache.directory.server.dhcp.AbstractDhcpTestCase.java
@Nonnull protected ByteBuffer getByteBufferFromFile(@Nonnull String file) throws IOException { URL resource = Resources.getResource(getClass(), file); byte[] data = Resources.toByteArray(resource); return ByteBuffer.wrap(data); }
From source file:org.apache.provisionr.api.util.BuilderWithOptions.java
/** * Load options from a properties file available as a resource on the classpath *//* ww w .j a v a2 s . co m*/ public P optionsFromResource(String resource) { Properties properties = new Properties(); ByteArrayInputStream in = null; try { in = new ByteArrayInputStream(Resources.toByteArray(Resources.getResource(resource))); properties.load(in); return options(properties); } catch (IOException e) { throw Throwables.propagate(e); } finally { Closeables.closeQuietly(in); } }
From source file:com.buildria.mocking.builder.action.ResponseActionSpec.java
public ResponseActionSpec withRawBody(URL url) throws IOException { return withRawBody(Resources.toByteArray(url)); }
From source file:domainapp.fixture.scenarios.spreadsheets.CreateUsingSpreadsheet.java
@Override protected void execute(final ExecutionContext ec) { // defaults/*from w w w .ja va2 s.c om*/ final String resourceName = checkParam("resourceName", ec, String.class); // validate final URL resource = Resources.getResource(getClass(), resourceName); byte[] bytes; try { bytes = Resources.toByteArray(resource); } catch (IOException e) { throw new IllegalArgumentException("Could not read from resource: " + resourceName); } // execute final Blob blob = new Blob(resourceName, ExcelService.XSLX_MIME_TYPE, bytes); final List<T> objects = excelService.fromExcel(blob, cls); for (final T obj : objects) { doPersist(obj); this.objects.add(obj); } }
From source file:org.isisaddons.module.docx.fixture.dom.templates.CustomerConfirmation.java
@PostConstruct public void init() throws IOException, LoadTemplateException { final byte[] bytes = Resources .toByteArray(Resources.getResource(this.getClass(), "CustomerConfirmation.docx")); wordprocessingMLPackage = docxService.loadPackage(new ByteArrayInputStream(bytes)); }