protected byte[] load() throws IOException { return IOUtils.toByteArray(in); }
public static byte[] gunzip(byte[] gzippedData) throws IOException { GZIPInputStream is = new GZIPInputStream(new ByteArrayInputStream(gzippedData)); byte[] data = IOUtils.toByteArray(is); is.close(); return data; } }
public static byte[] gunzip(byte[] gzippedData) throws IOException { GZIPInputStream is = new GZIPInputStream(new ByteArrayInputStream(gzippedData)); byte[] data = IOUtils.toByteArray(is); is.close(); return data; } }
public static byte[] gunzip(byte[] gzippedData) throws IOException { GZIPInputStream is = new GZIPInputStream(new ByteArrayInputStream(gzippedData)); byte[] data = IOUtils.toByteArray(is); is.close(); return data; } }
public static byte[] toByteArray(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { return toByteArray(is); } finally { close(is); } }
public static byte[] toByteArray(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { return IOUtils.toByteArray(is); } finally { IOUtils.close(is); } }
public static byte[] toByteArray(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { return IOUtils.toByteArray(is); } finally { IOUtils.close(is); } }
private String exec(HttpUriRequest req) throws IOException { final CloseableHttpResponse response = httpClient.execute(req); try { checkStatus(response); if (response.getEntity() != null) { return StringUtils.utf8(IOUtils.toByteArray(response.getEntity().getContent())); } else { return null; } } finally { response.close(); } }
/** * Check if a user has been linked against your website. * Use this to verify the user has been successfully linked to your website/service after he's been redirected to * the redirectUrl you specified in {@link #linkUser(String, URL, String, URL)}. * * @param serviceId Website serviceId * @param userRef User reference (generally the user's username on your website) * @return true if the user is linked against your website * @throws IOException If error occurred performing the operation */ public boolean isUserLinked(String serviceId, String userRef) throws IOException { final HttpGet req = new HttpGet(linkUserUrl(serviceId, userRef)); try { final CloseableHttpResponse response = httpClient.execute(req); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 404) { return false; } else if (statusCode == 200) { return Boolean.parseBoolean(StringUtils.utf8(IOUtils.toByteArray(response.getEntity().getContent()))); } else { throw new IOException("Server returned " + response.getStatusLine()); } } finally { req.releaseConnection(); } }
/** * Link an IDVKey user to your service/website. * You need to call this operation before a user on your website can use his IDVKey device * * @param serviceId Your website serviceId * @param redirectUrl The URL to which the user's browser will be redirected to after he's approved the link * @param userRef User reference (generally the user's username on your website) * @param cancelUrl URL to redirect user to should he wish to cancel the linking * @return URL you should redirect your user's browser to, in order for him to approve the linking * @throws IOException If the server returned an error * @throws UserAlreadyLinkedException if the user was already linked */ public URL linkUser(String serviceId, URL redirectUrl, String userRef, URL cancelUrl) throws IOException, UserAlreadyLinkedException { final HttpPost req = new HttpPost(linkUserUrl(serviceId, userRef, redirectUrl, cancelUrl)); try { final CloseableHttpResponse response = httpClient.execute(req); final int retCode = response.getStatusLine().getStatusCode(); if (retCode == 409) { throw new UserAlreadyLinkedException(); } else if (retCode < 200 || retCode > 299) { throw new IOException("Server returned " + response.getStatusLine()); } return new URL(StringUtils.utf8(IOUtils.toByteArray(response.getEntity().getContent()))); } finally { req.releaseConnection(); } }