Package org.apache.jena.atlas.io
Class IO
- java.lang.Object
-
- org.apache.jena.atlas.io.IO
-
public class IO extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description IO()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.ReaderasASCII(java.io.InputStream in)Create a unbuffered reader that uses ASCII encodingstatic java.io.WriterasASCII(java.io.OutputStream out)Create a writer that uses ASCII encodingstatic java.io.BufferedReaderasBufferedUTF8(java.io.InputStream in)Create an buffered reader that uses UTF-8 encodingstatic java.io.WriterasBufferedUTF8(java.io.OutputStream out)Create a writer that uses UTF-8 encoding and is buffered.static java.io.PrintWriterasPrintWriterUTF8(java.io.OutputStream out)Create a print writer that uses UTF-8 encodingstatic java.io.ReaderasUTF8(java.io.InputStream in)Create an unbuffered reader that uses UTF-8 encodingstatic java.io.WriterasUTF8(java.io.OutputStream out)Create a writer that uses UTF-8 encodingstatic java.lang.StringbyteBufferToString(java.nio.ByteBuffer bb)ByteBuffer to Stringstatic voidclose(java.io.Closeable resource)static voidclose(AWriter resource)static voidclose(IndentedWriter resource)static voidclose(Closeable resource)static voidcloseSilent(java.io.Closeable resource)static voidcloseSilent(AWriter resource)static voidcloseSilent(IndentedWriter resource)static voidcloseSilent(Closeable resource)static voiddeleteAll(java.nio.file.Path start)Delete everything from aPathstart point, including the path itself.static voidexception(java.io.IOException ex)Throw a RuntimeIOException - this function is guaranteed not to return normallystatic voidexception(java.lang.String message)Throw a RuntimeIOException - this function is guaranteed not to return normallystatic voidexception(java.lang.String msg, java.io.IOException ex)Throw a RuntimeIOException - this function is guaranteed not to return normallystatic booleanexists(java.lang.String directory)static java.lang.StringfilenameNoCompression(java.lang.String filename)The filename without any compression extension, or the original filename.static voidflush(java.io.OutputStream out)static voidflush(java.io.Writer out)static voidflush(AWriter out)static booleanisDirectory(java.lang.String directory)static booleanisEmptyDirectory(java.lang.String directory)static java.io.InputStreamopenFile(java.lang.String filename)Open an input stream to a file.static java.io.ReaderopenFileASCII(java.lang.String filename)Open an ASCII Reader for a file.static java.io.InputStreamopenFileBuffered(java.lang.String filename)Open an input stream to a file and buffer it.static java.io.InputStreamopenFileEx(java.lang.String filename)Open an input stream to a file; do not mask IOExceptions.static java.io.ReaderopenFileUTF8(java.lang.String filename)Open a UTF8 Reader for a file.static java.io.OutputStreamopenOutputFile(java.lang.String filename)Open a file for output - may include adding gzip processing.static java.io.OutputStreamopenOutputFileEx(java.lang.String filename)Open an input stream to a file; do not mask IOExceptions.static byte[]readWholeFile(java.io.InputStream in)static java.lang.StringreadWholeFileAsUTF8(java.io.InputStream in)Read a whole stream as UTF-8static java.lang.StringreadWholeFileAsUTF8(java.lang.String filename)Read a whole file as UTF-8static voidskipToEnd(java.io.InputStream input)Skip to the end of the InputStream, discarding input.static java.nio.ByteBufferstringToByteBuffer(java.lang.String str)String to ByteBuffer as UTF-8 bytesstatic java.lang.StringuniqueFilename(java.lang.String directory, java.lang.String base, java.lang.String ext)static AWriterwrap(java.io.Writer w)Wrap in a general writer interfacestatic AWriterwrapASCII(java.io.OutputStream out)Wrap in a general writer interfacestatic AWriterwrapUTF8(java.io.OutputStream out)Wrap in a general writer interfacestatic voidwriteStringAsUTF8(java.io.OutputStream out, java.lang.String content)Write a string into anOutputStreamas UTF-8.static voidwriteStringAsUTF8(java.lang.String filename, java.lang.String content)Write a string to a file as UTF-8.
-
-
-
Field Detail
-
EOF
public static final int EOF
- See Also:
- Constant Field Values
-
UNSET
public static final int UNSET
- See Also:
- Constant Field Values
-
-
Method Detail
-
openFile
public static java.io.InputStream openFile(java.lang.String filename)
Open an input stream to a file.If the filename is null or "-", return System.in If the filename ends in .gz, wrap in GZIPInputStream
Throws
RuntimeIOExceptionon failure to open.
-
openFileBuffered
public static java.io.InputStream openFileBuffered(java.lang.String filename)
Open an input stream to a file and buffer it. If the filename is null or "-", return System.in If the filename ends in .gz, wrap in GZIPInputStream. If using thisInputStreamwith anInputStreamReader(e.g. to get UTF-8), there is no need to buffer theInputStream. Instead, buffer theReader.Throws
RuntimeIOExceptionon failure to open.
-
openFileEx
public static java.io.InputStream openFileEx(java.lang.String filename) throws java.io.IOException, java.io.FileNotFoundExceptionOpen an input stream to a file; do not mask IOExceptions. If the filename is null or "-", return System.in If the filename ends in .gz, wrap in GZIPInputStream- Parameters:
filename-- Throws:
java.io.FileNotFoundExceptionjava.io.IOException
-
filenameNoCompression
public static java.lang.String filenameNoCompression(java.lang.String filename)
The filename without any compression extension, or the original filename. It tests for compression types handled byopenFileEx(java.lang.String).
-
openFileUTF8
public static java.io.Reader openFileUTF8(java.lang.String filename)
Open a UTF8 Reader for a file. If the filename is null or "-", use System.in If the filename ends in .gz, use GZIPInputStream
-
openFileASCII
public static java.io.Reader openFileASCII(java.lang.String filename)
Open an ASCII Reader for a file. If the filename is null or "-", use System.in If the filename ends in .gz, use GZIPInputStream
-
asUTF8
public static java.io.Reader asUTF8(java.io.InputStream in)
Create an unbuffered reader that uses UTF-8 encoding
-
asASCII
public static java.io.Reader asASCII(java.io.InputStream in)
Create a unbuffered reader that uses ASCII encoding
-
asBufferedUTF8
public static java.io.BufferedReader asBufferedUTF8(java.io.InputStream in)
Create an buffered reader that uses UTF-8 encoding
-
asUTF8
public static java.io.Writer asUTF8(java.io.OutputStream out)
Create a writer that uses UTF-8 encoding
-
asASCII
public static java.io.Writer asASCII(java.io.OutputStream out)
Create a writer that uses ASCII encoding
-
asBufferedUTF8
public static java.io.Writer asBufferedUTF8(java.io.OutputStream out)
Create a writer that uses UTF-8 encoding and is buffered.
-
openOutputFile
public static java.io.OutputStream openOutputFile(java.lang.String filename)
Open a file for output - may include adding gzip processing.Throws
RuntimeIOExceptionon failure to open.
-
openOutputFileEx
public static java.io.OutputStream openOutputFileEx(java.lang.String filename) throws java.io.FileNotFoundException, java.io.IOExceptionOpen an input stream to a file; do not mask IOExceptions. If the filename ends in .gz, wrap in GZIPOutputStream- Parameters:
filename-- Throws:
java.io.FileNotFoundException- If the output can't be opened.java.io.IOException- for bad gzip encoded data
-
wrap
public static AWriter wrap(java.io.Writer w)
Wrap in a general writer interface
-
wrapUTF8
public static AWriter wrapUTF8(java.io.OutputStream out)
Wrap in a general writer interface
-
wrapASCII
public static AWriter wrapASCII(java.io.OutputStream out)
Wrap in a general writer interface
-
asPrintWriterUTF8
public static java.io.PrintWriter asPrintWriterUTF8(java.io.OutputStream out)
Create a print writer that uses UTF-8 encoding
-
isEmptyDirectory
public static boolean isEmptyDirectory(java.lang.String directory)
-
exists
public static boolean exists(java.lang.String directory)
-
isDirectory
public static boolean isDirectory(java.lang.String directory)
-
close
public static void close(Closeable resource)
-
closeSilent
public static void closeSilent(Closeable resource)
-
close
public static void close(java.io.Closeable resource)
-
closeSilent
public static void closeSilent(java.io.Closeable resource)
-
close
public static void close(AWriter resource)
-
closeSilent
public static void closeSilent(AWriter resource)
-
close
public static void close(IndentedWriter resource)
-
closeSilent
public static void closeSilent(IndentedWriter resource)
-
exception
public static void exception(java.lang.String message)
Throw a RuntimeIOException - this function is guaranteed not to return normally
-
exception
public static void exception(java.io.IOException ex)
Throw a RuntimeIOException - this function is guaranteed not to return normally
-
exception
public static void exception(java.lang.String msg, java.io.IOException ex)Throw a RuntimeIOException - this function is guaranteed not to return normally
-
flush
public static void flush(java.io.OutputStream out)
-
flush
public static void flush(java.io.Writer out)
-
flush
public static void flush(AWriter out)
-
readWholeFile
public static byte[] readWholeFile(java.io.InputStream in)
-
readWholeFileAsUTF8
public static java.lang.String readWholeFileAsUTF8(java.lang.String filename)
Read a whole file as UTF-8- Parameters:
filename-- Returns:
- String
-
readWholeFileAsUTF8
public static java.lang.String readWholeFileAsUTF8(java.io.InputStream in)
Read a whole stream as UTF-8- Parameters:
in- InputStream to be read- Returns:
- String
-
writeStringAsUTF8
public static void writeStringAsUTF8(java.lang.String filename, java.lang.String content) throws java.io.IOExceptionWrite a string to a file as UTF-8. The file is closed after the operation.- Parameters:
filename-content- String to be written- Throws:
java.io.IOException
-
writeStringAsUTF8
public static void writeStringAsUTF8(java.io.OutputStream out, java.lang.String content) throws java.io.IOExceptionWrite a string into anOutputStreamas UTF-8.- Parameters:
out- OutputStream destination.content- String to be written- Throws:
java.io.IOException
-
stringToByteBuffer
public static java.nio.ByteBuffer stringToByteBuffer(java.lang.String str)
String to ByteBuffer as UTF-8 bytes
-
byteBufferToString
public static java.lang.String byteBufferToString(java.nio.ByteBuffer bb)
ByteBuffer to String
-
uniqueFilename
public static java.lang.String uniqueFilename(java.lang.String directory, java.lang.String base, java.lang.String ext)
-
deleteAll
public static void deleteAll(java.nio.file.Path start)
Delete everything from aPathstart point, including the path itself. This function works on files or directories. This function does not follow symbolic links.
-
skipToEnd
public static void skipToEnd(java.io.InputStream input)
Skip to the end of the InputStream, discarding input.
-
-