public void close () { StreamHelper.close (m_aHttpClient); m_aHttpClient = null; }
@Nonnull private static NonBlockingByteArrayInputStream _getCachedInputStream (@Nonnull @WillClose final InputStream aIS) { return new NonBlockingByteArrayInputStream (StreamHelper.getAllBytes (aIS)); }
@Nullable public byte [] getContent (@Nonnull final DataSource aDS) throws IOException { return StreamHelper.getAllBytes (StreamHelper.getBuffered (aDS.getInputStream ())); }
@Nonnull public MarkdownProcessingResult process (@Nonnull final InputStream aIS) throws IOException { ValueEnforcer.notNull (aIS, "InputStream"); return process (StreamHelper.getBuffered (StreamHelper.createReader (aIS, m_aConfig.getEncoding ()))); }
if (!StreamHelper.isKnownEOFException (ex)) LOGGER.error ("Failed to write Excel workbook to output stream " + aOS, ex); return ESuccess.FAILURE; StreamHelper.close (aOS);
StreamHelper.copyInputStreamToOutputStreamWithLimit (aIS, aMDNStream, nContentLength); else StreamHelper.copyInputStreamToOutputStream (aIS, aMDNStream); StreamHelper.close (aMDNStream);
final Reader aReader = StreamHelper.createReader (aISAndBOM.getInputStream (), aStreamCharset); try StreamHelper.close (aReader);
StreamHelper.copyInputStreamToOutputStream (aMsg.getData ().getInputStream (), aFOS); StreamHelper.close (aFOS);
@Nonnull @OverrideOnDemand public OutputStream createOutputStream () throws IOException { return StreamHelper.getBuffered (m_aSocket.getOutputStream ()); }
@Nonnegative public static long copy (@Nonnull @WillClose final InputStream aIS, @Nonnull @WillNotClose final OutputStream aOS) { final MutableLong aML = new MutableLong (0); StreamHelper.copyInputStreamToOutputStream (aIS, aOS, aML); return aML.longValue (); }
@Nullable public BufferedReader getReader () { if (m_aContent == null) return null; final InputStream aIS = new NonBlockingByteArrayInputStream (m_aContent); final Reader aReader = StreamHelper.createReader (aIS, getCharacterEncodingObjOrDefault ()); return new BufferedReader (aReader); }
public void onAjaxExecutionException (@Nullable final IAjaxInvoker aAjaxInvoker, @Nullable final String sFunctionName, @Nonnull final IAjaxExecutor aAjaxExecutor, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final Exception ex) { if (ex instanceof IOException) { if (!StreamHelper.isKnownEOFException (ex)) LOGGER.error ("Error writing result of Ajax function '" + sFunctionName + "' with " + aAjaxExecutor, ex); } else { LOGGER.error ("Error invoking Ajax function '" + sFunctionName + "' on " + aAjaxExecutor, ex); if (GlobalDebug.isDebugMode ()) RequestLogger.logRequestComplete (aRequestScope.getRequest ()); } } }
StreamHelper.copyInputStreamToOutputStreamWithLimit (aConnIS, aMDNStream, nContentLength); else StreamHelper.copyInputStreamToOutputStream (aConnIS, aMDNStream); StreamHelper.close (aMDNStream);
final Reader aReader = StreamHelper.createReader (aIS, aCharsetToUse); final ECSSVersion eVersion = aSettings.getCSSVersion (); try StreamHelper.close (aReader);
@Nonnull public InputStream getNonUpwardClosingInputStream () throws IOException { // Use "NonClosing" internally to that the returned stream is easily // discovered as "buffered" return StreamHelper.getBuffered (new NonClosingInputStream (m_aSocket.getInputStream ())); } }
/** * Stores the content of the input {@link InputStream} in a temporary file (in * the system temporary directory. * * @param aIS * {@link InputStream} to read from * @param sName * name to use in the temporary file to link it to the delivered * message. May be null * @return The created {@link File} * @throws IOException * in case of IO error */ @Nonnull protected static File storeContentToTempFile (@Nonnull final InputStream aIS, @Nonnull final String sName) throws IOException { // create temp file and write steam content to it // name may contain ":" on Windows and that would fail the tests! final String sSuffix = FilenameHelper.getAsSecureValidASCIIFilename (sName != null ? sName : "tmp"); final File aDestFile = File.createTempFile ("AS2TempSharedFileIS", sSuffix); try (final FileOutputStream aOS = new FileOutputStream (aDestFile)) { final MutableLong aCount = new MutableLong (0); StreamHelper.copyInputStreamToOutputStream (aIS, aOS, aCount); if (LOGGER.isInfoEnabled ()) LOGGER.info (aCount.longValue () + " bytes copied to " + aDestFile.getAbsolutePath ()); } return aDestFile; }
/** * Read the CSS from the passed {@link InputStream}. * * @param aIS * The input stream to use. Will be closed automatically after reading * - independent of success or error. May not be <code>null</code>. * @param aCharset * The charset to be used. May not be <code>null</code>. * @param eVersion * The CSS version to use. May not be <code>null</code>. * @return <code>null</code> if reading failed, the CSS declarations * otherwise. * @since 3.7.4 */ @Nullable public static CSSDeclarationList readFromStream (@Nonnull @WillClose final InputStream aIS, @Nonnull final Charset aCharset, @Nonnull final ECSSVersion eVersion) { return readFromReader (StreamHelper.createReader (aIS, aCharset), new CSSReaderSettings ().setCSSVersion (eVersion)); }
public void onAPIExecutionException (@Nonnull final IAPIInvoker aInvoker, @Nonnull final InvokableAPIDescriptor aInvokableDescriptor, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final Throwable t) { if (t instanceof IOException) { if (!StreamHelper.isKnownEOFException (t)) LOGGER.error ("Error writing result of API '" + aInvokableDescriptor.getPath () + "' with " + aInvokableDescriptor, t); } else { LOGGER.error ("Error invoking API '" + aInvokableDescriptor.getPath () + "' on " + aInvokableDescriptor, t); if (GlobalDebug.isDebugMode ()) RequestLogger.logRequestComplete (aRequestScope.getRequest ()); } } }
@Override public final void close () throws IOException { StreamHelper.close (m_aZipInputStream); m_aZipInputStream = null; }
@Nonnull private static Document _readXML (@Nonnull final InputStream aRequestIS) { if (isDebug ()) { final byte [] aBytes = StreamHelper.getAllBytes (aRequestIS); final Charset aCharset = Charset.defaultCharset (); LOGGER.info ("GOT[" + aCharset.name () + "]:\n" + new String (aBytes, aCharset)); return DOMReader.readXMLDOM (aBytes); } return DOMReader.readXMLDOM (aRequestIS); }