Class Utils
- java.lang.Object
-
- com.epam.reportportal.utils.files.Utils
-
public class Utils extends java.lang.ObjectFile utilities.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopyFiles(java.io.File source, java.io.File dest)Copies aFileintoFilein binary mode.static intcopyStreams(java.io.InputStream is, java.io.OutputStream os)Copies anInputStreaminto onOutputStreambyte-to-byte.static intcopyStreams(java.io.InputStream is, java.io.OutputStream os, int bufferSize)Copies anInputStreaminto onOutputStreambyte-to-byte.static TypeAwareByteSourcegetFile(java.io.File file)Locates and reads a file either by a direct path or by a relative path in classpath.static TypeAwareByteSourcegetFile(java.net.URI uri)Locates and reads a file either by a direct path or by a relative path in classpath.static ByteSourcegetFileAsByteSource(java.io.File file)Locates and reads a file either by a direct path or by a relative path in classpath.static java.net.URLgetResource(java.lang.String path)Finds a resource with a given name.static java.io.InputStreamgetResourceAsStream(java.lang.String path)Returns an input stream for reading the specified resource.static byte[]readFileToBytes(java.io.File file)Reads aFileinto an array of bytes.static byte[]readInputStreamToBytes(java.io.InputStream is)Reads anInputStreaminto an array of bytes.static byte[]readInputStreamToBytes(java.io.InputStream is, int bufferSize)Reads anInputStreaminto an array of bytes.static java.lang.StringreadInputStreamToString(java.io.InputStream is)Reads anInputStreaminto aString.
-
-
-
Method Detail
-
readInputStreamToString
@Nonnull public static java.lang.String readInputStreamToString(@Nonnull java.io.InputStream is) throws java.io.IOExceptionReads anInputStreaminto aString. Uses UTF-8 encoding and 10 kilobytes buffer by default.- Parameters:
is- a stream to read from- Returns:
- the result
- Throws:
java.io.IOException- in case of a read error
-
readInputStreamToBytes
public static byte[] readInputStreamToBytes(@Nonnull java.io.InputStream is) throws java.io.IOExceptionReads anInputStreaminto an array of bytes. Uses 10 kilobytes buffer by default.- Parameters:
is- a stream to read from- Returns:
- the result
- Throws:
java.io.IOException- in case of a read error
-
copyStreams
public static int copyStreams(@Nonnull java.io.InputStream is, @Nonnull java.io.OutputStream os, int bufferSize) throws java.io.IOExceptionCopies anInputStreaminto onOutputStreambyte-to-byte.- Parameters:
is- a stream to read fromos- a stream to write tobufferSize- size of read buffer in bytes- Returns:
- bytes copied
- Throws:
java.io.IOException- in case of a read error
-
copyStreams
public static int copyStreams(@Nonnull java.io.InputStream is, @Nonnull java.io.OutputStream os) throws java.io.IOExceptionCopies anInputStreaminto onOutputStreambyte-to-byte.- Parameters:
is- a stream to read fromos- a stream to write to- Returns:
- bytes copied
- Throws:
java.io.IOException- in case of a read error
-
readInputStreamToBytes
public static byte[] readInputStreamToBytes(@Nonnull java.io.InputStream is, int bufferSize) throws java.io.IOExceptionReads anInputStreaminto an array of bytes.- Parameters:
is- a stream to read frombufferSize- size of read buffer in bytes- Returns:
- the result
- Throws:
java.io.IOException- in case of a read error
-
readFileToBytes
public static byte[] readFileToBytes(@Nonnull java.io.File file) throws java.io.IOExceptionReads aFileinto an array of bytes.- Parameters:
file- a file to read- Returns:
- the result
- Throws:
java.io.IOException- in case of a read error, or a file not found
-
getResourceAsStream
@Nonnull public static java.io.InputStream getResourceAsStream(@Nonnull java.lang.String path) throws java.io.FileNotFoundExceptionReturns an input stream for reading the specified resource.- Parameters:
path- resource name or path to the resource- Returns:
- readable stream for the resource
- Throws:
java.io.FileNotFoundException- if no resource found
-
getResource
@Nonnull public static java.net.URL getResource(@Nonnull java.lang.String path) throws java.io.FileNotFoundExceptionFinds a resource with a given name.- Parameters:
path- resource name or path to the resource- Returns:
- location reference
- Throws:
java.io.FileNotFoundException- if no resource found
-
getFileAsByteSource
public static ByteSource getFileAsByteSource(@Nonnull java.io.File file) throws java.io.IOException
Locates and reads a file either by a direct path or by a relative path in classpath.- Parameters:
file- a file to locate and read- Returns:
- file data
- Throws:
java.io.IOException- in case of a read error, or a file not found
-
getFile
public static TypeAwareByteSource getFile(@Nonnull java.io.File file) throws java.io.IOException
Locates and reads a file either by a direct path or by a relative path in classpath.- Parameters:
file- a file to locate and read- Returns:
- file data and type
- Throws:
java.io.IOException- in case of a read error, or a file not found
-
getFile
public static TypeAwareByteSource getFile(@Nonnull java.net.URI uri) throws java.io.IOException
Locates and reads a file either by a direct path or by a relative path in classpath.- Parameters:
uri- a file to locate and read- Returns:
- file data and type
- Throws:
java.io.IOException- in case of a read error, or a file not found
-
copyFiles
public static void copyFiles(@Nonnull java.io.File source, @Nonnull java.io.File dest) throws java.io.IOExceptionCopies aFileintoFilein binary mode.- Parameters:
source- a stream to read fromdest- a stream to write to- Throws:
java.io.IOException- in case of a read/write error
-
-