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)); }
@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); } } }
@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); } }
public void refresh () throws OpenAS2Exception { try { load (FileHelper.getInputStream (new File (getFilename ()))); } catch (final Exception ex) { throw WrappedOpenAS2Exception.wrap (ex); } }
/** * 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; }
/** * @return An {@link InputStream} that can be used to retrieve the contents of * the file. */ @Nonnull public InputStream getInputStream () { if (isInMemory ()) { _ensureCachedContentIsPresent (); return new NonBlockingByteArrayInputStream (m_aCachedContent); } return FileHelper.getInputStream (m_aDFOS.getFile ()); }
@Nullable public static InputSource create (@Nonnull final IReadableResource aResource) { if (aResource instanceof FileSystemResource) { final File aFile = aResource.getAsFile (); if (aFile != null) { // Potentially use memory mapped files final InputSource ret = create (FileHelper.getInputStream (aFile)); if (ret != null) { // Ensure system ID is present - may be helpful for resource // resolution final URL aURL = aResource.getAsURL (); if (aURL != null) ret.setSystemId (aURL.toExternalForm ()); } return ret; } } return new ReadableResourceSAXInputSource (aResource); }
/** * Reads the state of this object during deserialization. * * @param aOIS * The stream from which the state should be read. * @throws IOException * if an error occurs. * @throws ClassNotFoundException * if class cannot be found. */ private void readObject (@Nonnull final ObjectInputStream aOIS) throws IOException, ClassNotFoundException { // read values aOIS.defaultReadObject (); try (final OutputStream aOS = getOutputStream ()) { if (m_aCachedContent != null) { aOS.write (m_aCachedContent); } else { final InputStream aIS = FileHelper.getInputStream (m_aDFOSFile); StreamHelper.copyInputStreamToOutputStream (aIS, aOS); FileOperations.deleteFile (m_aDFOSFile); m_aDFOSFile = null; } } m_aCachedContent = null; }
/** * Writes the data from this output stream to the specified output stream, * after it has been closed. * * @param aOS * output stream to write to. * @exception IOException * if this stream is not yet closed or an error occurs. */ public void writeTo (@Nonnull @WillNotClose final OutputStream aOS) throws IOException { // we may only need to check if this is closed if we are working with a file // but we should force the habit of closing whether we are working with // a file or memory. if (!m_bClosed) throw new IOException ("This stream is not closed"); if (isInMemory ()) { m_aMemoryOS.writeTo (aOS); } else { final InputStream aIS = FileHelper.getInputStream (m_aOutputFile); StreamHelper.copyInputStreamToOutputStream (aIS, aOS); } } }
try (final DataInputStream aOIS = new DataInputStream (FileHelper.getInputStream (aWALFile)))