Java Code Examples for com.helger.commons.io.stream.StreamHelper#writeStream()

The following examples show how to use com.helger.commons.io.stream.StreamHelper#writeStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IFileRelativeIO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Helper function for saving a file with correct error handling.
 *
 * @param sRelativePath
 *        name of the file. May not be <code>null</code>.
 * @param eAppend
 *        Appending mode. May not be <code>null</code>.
 * @param aBytes
 *        the bytes to be written. May not be <code>null</code>.
 * @return {@link ESuccess}
 */
@Nonnull
default ESuccess writeFile (@Nonnull final String sRelativePath,
                            @Nonnull final EAppend eAppend,
                            @Nonnull final byte [] aBytes)
{
  // save to file
  final OutputStream aOS = getOutputStream (sRelativePath, eAppend);
  if (aOS == null)
    return ESuccess.FAILURE;

  // Close the OS automatically!
  return StreamHelper.writeStream (aOS, aBytes);
}
 
Example 2
Source File: SimpleFileIO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ESuccess writeFile (@Nonnull final File aFile,
                                  @Nonnull final byte [] aContent,
                                  @Nonnegative final int nOffset,
                                  @Nonnegative final int nLength)
{
  final OutputStream aFOS = FileHelper.getOutputStream (aFile);
  return aFOS == null ? ESuccess.FAILURE : StreamHelper.writeStream (aFOS, aContent, nOffset, nLength);
}
 
Example 3
Source File: SimpleFileIO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ESuccess writeFile (@Nonnull final File aFile,
                                  @Nonnull final String sContent,
                                  @Nonnull final Charset aCharset)
{
  final OutputStream aFOS = FileHelper.getOutputStream (aFile);
  return aFOS == null ? ESuccess.FAILURE : StreamHelper.writeStream (aFOS, sContent, aCharset);
}
 
Example 4
Source File: SimpleFileIO.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static ESuccess writeFile (@Nonnull final File aFile, @Nonnull final byte [] aContent)
{
  final OutputStream aFOS = FileHelper.getOutputStream (aFile);
  return aFOS == null ? ESuccess.FAILURE : StreamHelper.writeStream (aFOS, aContent);
}