/** * If the request body contains data that is valid JSON, all JSON properties will be added as * attributes. This mechanism can be used to transfer big data. */ private void initJSONBody() { LOG.debug("Performing JSON body initialization..."); // $NON-NLS-1$ try { if (this.m_aHttpRequest.getContentLength() > 0) { final MimeType aMimeType = MimeTypeParser.parseMimeType(this.m_aHttpRequest.getContentType()); if (aMimeType != null && aMimeType .getAsStringWithoutParameters() .equals(CMimeType.APPLICATION_JSON.getAsStringWithoutParameters())) { final String sJSON = StreamUtils.getAllBytesAsString( this.m_aHttpRequest.getInputStream(), CCharset.CHARSET_UTF_8_OBJ); final IJSONObject aJSON = JSONReader.parseObject(sJSON); for (final String sProperty : aJSON.getAllPropertyNames()) { setAttribute(sProperty, aJSON.getPropertyValueData(sProperty)); } } } } catch (final IOException aEx) { LOG.error("Error reading request body", aEx); // $NON-NLS-1$ } catch (final JSONParsingException aEx) { LOG.error("Error parsing JSON request body", aEx); // $NON-NLS-1$ } catch (final UnsupportedOperationException aEx) { // for mock requests it is not possible to get the content length } }
@Nonnull public static OpenAS2KeyStore read( @Nonnull final String filename, @Nonnull final char[] password, @Nonnull final ICryptoHelper cryptoHelper) throws Exception { final FileInputStream in = new FileInputStream(filename); try { return read(in, password, cryptoHelper); } finally { StreamUtils.close(in); } }
public boolean exists() { // 1. as file if (PROTOCOL_FILE.equals(m_aURL.getProtocol())) return getAsFile().exists(); // Not a file URL InputStream aIS = null; try { // 2. as stream aIS = getInputStream(); return aIS != null; } catch (final Exception ex) { // 3. no return false; } finally { StreamUtils.close(aIS); } }
@Nullable public Reader getReader(@Nonnull final Charset aCharset) { return StreamUtils.createReader(getInputStream(), aCharset); }