/** * @param aDumpFile * The file to dump to. */ public HTTPOutgoingDumperFileBased (@Nonnull final File aDumpFile) { super (FileHelper.getBufferedOutputStream (aDumpFile)); m_aDumpFile = aDumpFile; }
public AS2ServletSession (@Nonnull final File aFile) throws OpenAS2Exception { ValueEnforcer.notNull (aFile, "File"); if (!aFile.exists ()) throw new OpenAS2Exception ("AS2Session configuration file " + aFile.getAbsolutePath () + " does not exist!"); m_sBaseDirectory = aFile.getParentFile ().getAbsolutePath (); LOGGER.info ("Loading AS2 configuration file '" + aFile.getAbsolutePath ()); _load (FileHelper.getInputStream (aFile)); }
/** * Write the current workbook to a file * * @param aFile * The file to write to. May not be <code>null</code>. * @return {@link ESuccess} */ @Nonnull public ESuccess writeTo (@Nonnull final File aFile) { return writeTo (FileHelper.getOutputStream (aFile)); }
try (final OutputStream aOS = eCompressionMode.getCompressStream (FileHelper.getBufferedOutputStream (aRealFile))) StreamHelper.copyInputStreamToOutputStream (FileHelper.getBufferedInputStream (aSrcFile), aOS); ret.setSourceStreamProvider (HasInputStream.multiple ( () -> FileHelper.getBufferedInputStream (aRealFile))); return ret;
public HTTPIncomingDumperDirectoryBased (@Nonnull final File aDumpDirectory) { ValueEnforcer.notNull (aDumpDirectory, "DumpDirectory"); ValueEnforcer.isTrue (FileHelper.existsDir (aDumpDirectory), () -> "DumpDirectory " + aDumpDirectory + " does not exist!"); m_aDumpDirectory = aDumpDirectory; }
private void _scanDirectory (@Nonnull final File aDir) { for (final File aChild : FileHelper.getDirectoryContent (aDir)) { if (aChild.isDirectory ()) { // Shall we recurse into sub-directories? if (recursive) _scanDirectory (aChild); } else if (aChild.isFile () && CSSFilenameHelper.isCSSFilename (aChild.getName ()) && !_isAlreadyCompressed (aChild.getName ())) { // We're ready to rumble! _compressCSSFile (aChild); } } }
try (final OutputStream aOS = eCompressionMode.getCompressStream (FileHelper.getBufferedOutputStream (aRealFile))) ret.setSourceStreamProvider (HasInputStream.multiple ( () -> FileHelper.getBufferedInputStream (aRealFile)));
m_nSizeThreshold = ValueEnforcer.isGT0 (nSizeThreshold, "SizeThreshold"); m_aTempDir = aRepository != null ? aRepository : new File (SystemProperties.getTmpDir ()); if (!FileHelper.existsDir (m_aTempDir)) throw new IllegalArgumentException ("The tempory directory for file uploads is not existing: " + m_aTempDir.getAbsolutePath ());
private static void _iterate (@Nonnull final DefaultFolderTreeItem <String, File, ICommonsList <File>> aTreeItem, @Nonnull final File aDir, @Nullable final Predicate <? super File> aDirFilter, @Nullable final Predicate <? super File> aFileFilter) { if (aDir != null) for (final File aChild : FileHelper.getDirectoryContent (aDir)) { if (aChild.isFile ()) { // file // Check against the optional filter if (aFileFilter == null || aFileFilter.test (aChild)) aTreeItem.getData ().add (aChild); } else if (aChild.isDirectory () && !FilenameHelper.isSystemInternalDirectory (aChild)) { // directory // Check against the optional filter if (aDirFilter == null || aDirFilter.test (aChild)) { // create item and recursively descend final DefaultFolderTreeItem <String, File, ICommonsList <File>> aChildItem = aTreeItem.createChildItem (aChild.getName (), new CommonsArrayList <> ()); _iterate (aChildItem, aChild, aDirFilter, aFileFilter); } } } }
@Nonnull public static OpenAS2KeyStore readKeyStore (@Nonnull final IKeyStoreType aKeyStoreType, @Nonnull final String sFilename, @Nonnull final char [] aPassword, @Nonnull final ICryptoHelper aCryptoHelper) throws Exception { final InputStream aIS = FileHelper.getInputStream (new File (sFilename)); if (aIS == null) throw new IllegalArgumentException ("Failed to open KeyStore '" + sFilename + "' for reading"); try { final KeyStore aKeyStore = aCryptoHelper.loadKeyStore (aKeyStoreType, aIS, aPassword); return new OpenAS2KeyStore (aKeyStore); } finally { StreamHelper.close (aIS); } }
void save (@Nonnull OutputStream aOS, @Nonnull char [] aPassword) throws OpenAS2Exception; }
try (final OutputStream aOS = FileHelper.getBufferedOutputStream (aTempFile)) ret.setSourceStreamProvider (HasInputStream.multiple ( () -> FileHelper.getBufferedInputStream (aTempFile)));
/** * Write the passed object to a {@link File}. * * @param aObject * The object to be written. May not be <code>null</code>. * @param aResultFile * The result file to be written to. May not be <code>null</code>. * @return {@link ESuccess} */ @Nonnull default ESuccess write (@Nonnull final JAXBTYPE aObject, @Nonnull final File aResultFile) { if (USE_JAXB_CHARSET_FIX) { final OutputStream aOS = FileHelper.getBufferedOutputStream (aResultFile); if (aOS == null) return ESuccess.FAILURE; return write (aObject, aOS); } return write (aObject, TransformResultFactory.create (aResultFile)); }
@Nonnull public static X509Certificate readX509Certificate (@Nonnull final String sFilename) throws CertificateException { final InputStream aIS = FileHelper.getInputStream (new File (sFilename)); if (aIS == null) throw new IllegalArgumentException ("Failed to open KeyStore '" + sFilename + "' for reading"); try { final CertificateFactory cf = CertificateFactory.getInstance ("X.509"); final Collection <? extends Certificate> c = cf.generateCertificates (aIS); return (X509Certificate) CollectionHelper.getFirstElement (c); } finally { StreamHelper.close (aIS); } } }
protected void writeToFile (@Nonnull final File aDestinationFile, @Nonnull final List <String> aHeaderLines, @Nonnull final byte [] aPayload, @Nullable final IBaseMessage aMsg) { LOGGER.info ("Dumping incoming HTTP request to file " + aDestinationFile.getAbsolutePath ()); try (final OutputStream aOS = FileHelper.getOutputStream (aDestinationFile)) { for (final String sHeaderLine : aHeaderLines) aOS.write ((sHeaderLine + CHttp.EOL).getBytes (CHttp.HTTP_CHARSET)); // empty line aOS.write (CHttp.EOL.getBytes (CHttp.HTTP_CHARSET)); // Add payload aOS.write (aPayload); } catch (final IOException ex) { LOGGER.error ("Failed to dump HTTP request to file " + aDestinationFile.getAbsolutePath () + " and message stub " + aMsg, ex); } }
StreamHelper.copyInputStreamToOutputStreamAndCloseOS (aIS, FileHelper.getBufferedOutputStream (aTempFile)); aResponseAttachment.setSourceStreamProvider (HasInputStream.multiple ( () -> FileHelper.getBufferedInputStream (aTempFile)));
m_dos = new DigestOutputStream (FileHelper.getBufferedOutputStream (m_aFile), digest); m_aPW = new TrapClosePrintWriter (m_dos, Options.getOutputEncoding ());
/** * Set the content of the {@link File} as a payload. If no charset is applied * ( <code>null</code>) no content type starting with "text/" may be used. The * name of the file is used as the payload file name. * * @param aFile * {@link File} to read the content from. Never <code>null</code>. * @param aCharset * Charset to use. If it is <code>null</code> the content is set as a * byte array, if not <code>null</code> the content is set as a String. * @return this */ @Nonnull public AS2ClientRequest setData (@Nonnull final File aFile, @Nullable final Charset aCharset) { ValueEnforcer.notNull (aFile, "File"); setData (FileHelper.getInputStream (aFile), aCharset); // Set filename by default setFilename (aFile.getName ()); return this; }
public static void writeKeyStore (@Nonnull final OpenAS2KeyStore aKeyStore, @Nonnull final String sFilename, @Nonnull final char [] aPassword) throws GeneralSecurityException, IOException { final OutputStream aOS = FileHelper.getOutputStream (new File (sFilename), EAppend.TRUNCATE); if (aOS == null) throw new IllegalArgumentException ("Failed to open KeyStore '" + sFilename + "' for writing"); try { aKeyStore.getKeyStore ().store (aOS, aPassword); } finally { StreamHelper.close (aOS); } }
public void refresh () throws OpenAS2Exception { try { load (FileHelper.getInputStream (new File (getFilename ()))); } catch (final Exception ex) { throw WrappedOpenAS2Exception.wrap (ex); } }