@Override public T readFrom(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> map, InputStream stream) throws IOException, WebApplicationException { String json = IoUtils.toString(stream); return objectMapper.readValue(json, type); }
public static byte[] toBytes(ZipInputStream zis) throws IOException { return toBytes(zis, 1024); }
public static File findDirNearCurrent(String dirName) { return findDirNear(currentDir(), dirName); }
public static String toString(File file) throws IOException { return toString(new FileReader(file)); }
public static byte[] toBytes(InputStream in) throws IOException { return toBytes(in, 1024); }
File currentDir = IoUtils.currentDir(); File moduleDir = IoUtils.findDirNear(currentDir, directoryName);
public static String toString(URI uri) throws IOException { File file = new File(uri); return toString(file); }
@Override public final byte[] getEnabledIcon() throws IOException { InputStream stream = getClass().getResourceAsStream("/org/tiogasolutions/push/plugins/"+ pluginName +"/icon-enabled.png"); return IoUtils.toBytes(stream); }
public static String toString(URL url) throws IOException { try { return toString(url.toURI()); } catch (URISyntaxException e) { throw new IOException(e); } }
@Override public final byte[] getDisabledIcon() throws IOException { InputStream stream = getClass().getResourceAsStream("/org/tiogasolutions/push/plugins/"+ pluginName +"/icon-disabled.png"); return IoUtils.toBytes(stream); } }
public static String toString(InputStream is) throws IOException { return toString(new BufferedReader(new InputStreamReader(is))); }
@Override public void writeTo(LocalResource localResource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { String view = localResource.getView(); String resource = "/push-server-app/view" + (view.startsWith("/") ? "" : "/") + view; InputStream is = getClass().getResourceAsStream(resource); if (is == null) { throw new NotFoundException("View: " + view); } byte[] bytes = IoUtils.toBytes(is); entityStream.write(bytes); } }
private void sendEmail(URL templateUrl, String emailAddress, String subject, String message) { try { String template = IoUtils.toString(templateUrl); String content = template.replace("${message-content}", message); // AwsUtils.sendEmail(subject, content, "Munchie Monster <support@munchiemonster.com>", new MunMonEmailAddress(emailAddress)); } catch (Exception e) { String msg = String.format("Exception sending email to %s", emailAddress); throw ApiException.internalServerError(msg, e); } }
public byte[] getBytes(String subUrl, Map<String, Object> queryMap, String...acceptedResponseTypes) throws IOException { Invocation.Builder builder = builder(subUrl, queryMap, acceptedResponseTypes); Response response = builder.get(Response.class); if (response.getStatus() == 404 && notFoundToNull) return null; assertResponse(response.getStatus()); InputStream in = (InputStream)response.getEntity(); return IoUtils.toBytes(in); }
private void updateCatalog() throws Exception { File currentDir = new File("").getAbsoluteFile(); File configDir = new File(currentDir, "/runtime/config/"); String fileName = String.format("route-catalog-%s.json", domainName); File jsonFile = new File(configDir, fileName); String json = IoUtils.toString(jsonFile); Response response = client.target(apiPath + "/v2/admin/domains").path(domainName).path("route-catalog") .request(MediaType.APPLICATION_JSON_TYPE) .put(Entity.entity(json, MediaType.APPLICATION_JSON_TYPE)); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.OK) { throw ApiException.fromCode(statusCode, "Update of route catalog FAILED: " + response.getStatusInfo()); } JOptionPane.showMessageDialog(null, "The catalog has been updated:\n" + jsonFile, "Catalog Updated", JOptionPane.INFORMATION_MESSAGE); }
@Override public void writeTo(LocalResource localResource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { String view = localResource.getView(); String resource = "/push-server-app/view" + (view.startsWith("/") ? "" : "/") + view; InputStream is = getClass().getResourceAsStream(resource); if (is == null) { throw new NotFoundException("View: " + view); } byte[] bytes = IoUtils.toBytes(is); entityStream.write(bytes); } }
public static LatLng getLatLng(String address, String city, String state, String zip) throws IOException { String url = "https://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address="; url += encodeUrl(String.format("%s, %s, %s %s", address, city, state, zip)); URLConnection connection = new URL(url).openConnection(); String data = IoUtils.toString(connection.getInputStream()); data = getTagContents(data, "location", 0); return new LatLng( getTagContents(data, "lat", 0), getTagContents(data, "lng", 0) ); } }
@Override public void writeTo(LocalResource localResource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { String view = localResource.getView(); String resource = "/push-server-app/view" + (view.startsWith("/") ? "" : "/") + view; InputStream is = getClass().getResourceAsStream(resource); if (is == null) { throw new NotFoundException("View: " + view); } byte[] bytes = IoUtils.toBytes(is); entityStream.write(bytes); } }