@Test public void testStoreContentToTempFile () throws Exception { final String inData = "123456"; final String name = "xxy"; try (final InputStream is = new NonBlockingByteArrayInputStream (inData.getBytes (StandardCharsets.ISO_8859_1))) { final File file = TempSharedFileInputStream.storeContentToTempFile (is, name); assertTrue ("Temp file exists", file.exists ()); assertTrue ("Temp file name includes given name", file.getName ().indexOf (name) > 0); FileOperations.deleteFileIfExisting (file); } }
@Nonnull protected static File storeContentToTempFile (@Nonnull @WillClose final InputStream aIS, @Nonnull final String sName) throws IOException { final String sSuffix = FilenameHelper.getAsSecureValidASCIIFilename (StringHelper.hasText (sName) ? 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 ()) { if (aCount.longValue () > 1024) LOGGER.info (aCount.longValue () + " bytes copied to " + aDestFile.getAbsolutePath ()); } } return aDestFile; }
TempSharedFileInputStream extends SharedFileInputStream { @Nonnull protected static File storeContentToTempFile (@Nonnull @WillClose final InputStream aIS, @Nonnull final String sName) throws IOException { final String sSuffix = FilenameHelper.getAsSecureValidASCIIFilename (StringHelper.hasText (sName) ? 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 ()) { if (aCount.longValue () > 1024) LOGGER.info (aCount.longValue () + " bytes copied to " + aDestFile.getAbsolutePath ()); } } return aDestFile; } }
TempSharedFileInputStream extends SharedFileInputStream { @Nonnull protected static File storeContentToTempFile (@Nonnull @WillClose final InputStream aIS, @Nonnull final String sName) throws IOException { final String sSuffix = FilenameHelper.getAsSecureValidASCIIFilename (StringHelper.hasText (sName) ? 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 ()) { if (aCount.longValue () > 1024) LOGGER.info (aCount.longValue () + " bytes copied to " + aDestFile.getAbsolutePath ()); } } return aDestFile; } private  TempSharedFileInputStream(@Nonnull final File aFile); }
TempSharedFileInputStream extends SharedFileInputStream { @Nonnull protected static File storeContentToTempFile (@Nonnull @WillClose final InputStream aIS, @Nonnull final String sName) throws IOException { final String sSuffix = FilenameHelper.getAsSecureValidASCIIFilename (StringHelper.hasText (sName) ? 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 ()) { if (aCount.longValue () > 1024) LOGGER.info (aCount.longValue () + " bytes copied to " + aDestFile.getAbsolutePath ()); } } return aDestFile; } private  TempSharedFileInputStream(@Nonnull final File aFile); @Override void close(); void closeAll(); @Nonnull static TempSharedFileInputStream getTempSharedFileInputStream(@Nonnull @WillClose final InputStream aIS,
                                                                        @Nonnull final String sName); }
TempSharedFileInputStream extends SharedFileInputStream { @Nonnull protected static File storeContentToTempFile (@Nonnull @WillClose final InputStream aIS, @Nonnull final String sName) throws IOException { final String sSuffix = FilenameHelper.getAsSecureValidASCIIFilename (StringHelper.hasText (sName) ? 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 ()) { if (aCount.longValue () > 1024) LOGGER.info (aCount.longValue () + " bytes copied to " + aDestFile.getAbsolutePath ()); } } return aDestFile; } private  TempSharedFileInputStream(@Nonnull final File aFile); @Override void close(); void closeAll(); @Nonnull static TempSharedFileInputStream getTempSharedFileInputStream(@Nonnull @WillClose final InputStream aIS,
                                                                        @Nonnull final String sName);  }