private static byte[] getRequestContent(HttpServletRequest aRequest) throws IOException { try (InputStream is = aRequest.getInputStream()) { return BinaryUtils.readStream(is, aRequest.getContentLength() >= 0 ? aRequest.getContentLength() : 0); } }
protected static KeyManager[] createKeyManagers() throws NoSuchAlgorithmException, NoSuchProviderException, KeyStoreException, FileNotFoundException, IOException, CertificateException, UnrecoverableKeyException, URISyntaxException { KeyStore ks = KeyStore.getInstance(DEFAULT_CETRS_STORE_TYPE); // get user password and file input stream char[] password = DEFAULT_KEYSTORE_PASSWORD.toCharArray(); File keyStoreFile = new File(StringUtils.join(File.separator, System.getProperty(ClientConstants.USER_HOME_PROP_NAME), ClientConstants.USER_HOME_PLATYPUS_DIRECTORY_NAME, SECURITY_SUBDIRECTORY, "keystore")); if (!keyStoreFile.exists()) { File keyPath = new File(StringUtils.join(File.separator, System.getProperty(ClientConstants.USER_HOME_PROP_NAME), ClientConstants.USER_HOME_PLATYPUS_DIRECTORY_NAME, SECURITY_SUBDIRECTORY)); keyPath.mkdirs(); keyStoreFile.createNewFile(); try (OutputStream keyOut = new FileOutputStream(keyStoreFile); InputStream keyIn = PlatypusConnection.class.getResourceAsStream("defaultKeystore")) { byte[] resData = BinaryUtils.readStream(keyIn, -1); keyOut.write(resData); } } if (keyStoreFile.exists()) { try (InputStream is = new FileInputStream(keyStoreFile)) { ks.load(is, password); } final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); keyManagerFactory.init(ks, password); return keyManagerFactory.getKeyManagers(); } else { throw new FileNotFoundException(KEYSTORE_MISING_MSG); } }
protected static TrustManager[] createTrustManagers() throws NoSuchAlgorithmException, NoSuchProviderException, KeyStoreException, FileNotFoundException, IOException, CertificateException, URISyntaxException { KeyStore ks = KeyStore.getInstance(DEFAULT_CETRS_STORE_TYPE); char[] password = getTrustStorePassword(); File trustStore = new File(StringUtils.join(File.separator, System.getProperty(ClientConstants.USER_HOME_PROP_NAME), ClientConstants.USER_HOME_PLATYPUS_DIRECTORY_NAME, SECURITY_SUBDIRECTORY, "truststore")); if (!trustStore.exists()) { File trustPath = new File(StringUtils.join(File.separator, System.getProperty(ClientConstants.USER_HOME_PROP_NAME), ClientConstants.USER_HOME_PLATYPUS_DIRECTORY_NAME, SECURITY_SUBDIRECTORY)); trustPath.mkdirs(); trustStore.createNewFile(); try (OutputStream trustOut = new FileOutputStream(trustStore); InputStream trustIn = PlatypusConnection.class.getResourceAsStream("emptyTruststore")) { byte[] resData = BinaryUtils.readStream(trustIn, -1); trustOut.write(resData); } } if (trustStore.exists()) { try (InputStream is = new FileInputStream(trustStore)) { ks.load(is, password); } final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(DEFAULT_TRUST_ALGORITHM); trustManagerFactory.init(ks); return wrapTrustManagers(ks, trustManagerFactory.getTrustManagers()); } else { throw new FileNotFoundException(TRUSTSTORE_MISSING_MSG); } }
/** * Returns data of the substream of the current tag as a byte array. * * @return the input stream to read the substream. * @throws java.io.IOException if an I/O error occurs. * @throws com.eas.proto.ProtoReaderException if the tag following the current tag is not TAG_STREAM, * which violates current rules for writing substreams to tagged streams. */ public byte[] getSubStreamData() throws IOException, ProtoReaderException { int tag = getNextTag(); if (tag != CoreTags.TAG_STREAM && tag != CoreTags.TAG_COMPRESSED_STREAM) { throw new ProtoReaderException(INVALID_TAG_MSG); } byte[] subStreamData = new byte[currentSize]; get(subStreamData, currentSize); if (tag == CoreTags.TAG_COMPRESSED_STREAM) { try (ZipInputStream zStream = new ZipInputStream(new ByteArrayInputStream(subStreamData))) { zStream.getNextEntry(); subStreamData = BinaryUtils.readStream(zStream, -1); zStream.read(subStreamData); } } return subStreamData; }
data = BinaryUtils.readStream(_is, -1); String contentType = conn.getContentType(); if (contentType != null) {
} else if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_NOT_MODIFIED) { try (InputStream in = conn.getInputStream()) { responseBody = BinaryUtils.readStream(in, -1); if (checkIfSecirutyForm(responseBody)) { redirectLocation = PlatypusHttpConstants.SECURITY_REDIRECT_LOCATION; response = new JsonExceptionResponse(); try (InputStream in = conn.getErrorStream()) { responseBody = BinaryUtils.readStream(in, -1);
@Override public void visit(ResourceRequest.Response rsp) throws Exception { if (responseCode == HttpURLConnection.HTTP_OK) { long timeStamp = conn.getLastModified(); rsp.setTimeStamp(new Date(timeStamp)); if (bodyContent != null) { rsp.setContent(bodyContent); } else { try (InputStream is = conn.getInputStream()) { byte[] content = BinaryUtils.readStream(is, -1); rsp.setContent(content); } } } else if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED) { rsp.setContent(null); rsp.setTimeStamp(null); } }
byte[] content = BinaryUtils.readStream(in, -1); int slashIdx = reportLocation.lastIndexOf("/"); String fileName = reportLocation.substring(slashIdx + 1);
try (ZipInputStream zStream = new ZipInputStream(new ByteArrayInputStream(data, dataOffset, size))) { zStream.getNextEntry(); byte[] subStreamData = BinaryUtils.readStream(zStream, -1); child = new ProtoStreamNode(tag, subStreamData, 0, subStreamData.length);
byte[] content = BinaryUtils.readStream(in, -1); int slashIdx = reportLocation.lastIndexOf("/"); String fileName = reportLocation.substring(slashIdx + 1);
if (value != null) { try (InputStream is = ((Blob) value).getBinaryStream()) { value = BinaryUtils.readStream(is, -1);