java.lang.Object
org.apache.jena.atlas.io.IO
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringabbreviate(InputStream in, Charset charset, int maxWidth, String abbrevMarker) Fully reads the next up to maxWidth + 1 characters from the stream and returns them as a string.static Stringabbreviate(Reader reader, int maxWidth, String abbrevMarker) Fully reads the next up to maxWidth + 1 characters from the reader and returns them as a string.static ReaderasASCII(InputStream in) Create a unbuffered reader that uses ASCII encodingstatic WriterasASCII(OutputStream out) Create a writer that uses ASCII encodingstatic BufferedReaderCreate an buffered reader that uses UTF-8 encodingstatic WriterCreate a writer that uses UTF-8 encoding and is buffered.static PrintWriterCreate a print writer that uses UTF-8 encodingstatic ReaderasUTF8(InputStream in) Create an unbuffered reader that uses UTF-8 encodingstatic WriterasUTF8(OutputStream out) Create a writer that uses UTF-8 encodingstatic StringByteBuffer to Stringstatic voidstatic voidstatic voidclose(IndentedWriter resource) static voidstatic voidcloseSilent(Closeable resource) static voidcloseSilent(AWriter resource) static voidcloseSilent(IndentedWriter resource) static voidcloseSilent(Closeable resource) static voidDelete everything from aPathstart point, including the path itself.static InputStreamensureBuffered(InputStream input) static OutputStreamensureBuffered(OutputStream output) static ReaderensureBuffered(Reader input) static WriterensureBuffered(Writer output) static voidexception(IOException ex) Throw a RuntimeIOException - this function is guaranteed not to return normallystatic voidThrow a RuntimeIOException - this function is guaranteed not to return normallystatic voidexception(String msg, IOException ex) Throw a RuntimeIOException - this function is guaranteed not to return normallystatic booleanstatic StringfilenameNoCompression(String filename) The filename without any compression extension, or the original filename.static voidflush(OutputStream out) static voidstatic voidstatic booleanisDirectory(String directory) static booleanisEmptyDirectory(String directory) static InputStreamOpen an input stream to a file.static ReaderopenFileASCII(String filename) Open an ASCII Reader for a file.static InputStreamopenFileBuffered(String filename) Open an input stream to a file and buffer it.static InputStreamopenFileEx(String filename) Open an input stream to a file; do not mask IOExceptions.static ReaderopenFileUTF8(String filename) Open a UTF8 Reader for a file.static OutputStreamopenOutputFile(String filename) Open a file for output - may include adding gzip processing.static OutputStreamopenOutputFileEx(String filename) Open an input stream to a file; do not mask IOExceptions.static byte[]static StringRead a whole stream as UTF-8static StringreadWholeFileAsUTF8(String filename) Read a whole file as UTF-8static voidskipToEnd(InputStream input) Skip to the end of the InputStream, discarding input.static voidSkip to the end of the Reader, discarding input.static ByteBufferstringToByteBuffer(String str) String to ByteBuffer as UTF-8 bytesstatic StringuniqueFilename(String directory, String base, String ext) static AWriterWrap in a general writer interfacestatic AWriterwrapASCII(OutputStream out) Wrap in a general writer interfacestatic AWriterwrapUTF8(OutputStream out) Wrap in a general writer interfacestatic voidwriteStringAsUTF8(OutputStream out, String content) Write a string into anOutputStreamas UTF-8.static voidwriteStringAsUTF8(String filename, String content) Write a string to a file as UTF-8.
-
Field Details
-
EOF
public static final int EOF- See Also:
-
UNSET
public static final int UNSET- See Also:
-
-
Constructor Details
-
IO
public IO()
-
-
Method Details
-
openFile
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
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
Open 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 If the filename ends in .bz2, wrap in BZip2CompressorInputStream- Parameters:
filename-- Throws:
FileNotFoundExceptionIOException
-
filenameNoCompression
The filename without any compression extension, or the original filename. It tests for compression types handled byopenFileEx(java.lang.String). -
openFileUTF8
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
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
Create an unbuffered reader that uses UTF-8 encoding -
asASCII
Create a unbuffered reader that uses ASCII encoding -
asBufferedUTF8
Create an buffered reader that uses UTF-8 encoding -
asUTF8
Create a writer that uses UTF-8 encoding -
asASCII
Create a writer that uses ASCII encoding -
asBufferedUTF8
Create a writer that uses UTF-8 encoding and is buffered. -
openOutputFile
Open a file for output - may include adding gzip processing.Throws
RuntimeIOExceptionon failure to open. -
openOutputFileEx
public static OutputStream openOutputFileEx(String filename) throws FileNotFoundException, IOException Open an input stream to a file; do not mask IOExceptions. If the filename ends in .gz, wrap in GZIPOutputStream- Parameters:
filename-- Throws:
FileNotFoundException- If the output can't be opened.IOException- for bad gzip encoded data
-
wrap
Wrap in a general writer interface -
wrapUTF8
Wrap in a general writer interface -
wrapASCII
Wrap in a general writer interface -
asPrintWriterUTF8
Create a print writer that uses UTF-8 encoding -
isEmptyDirectory
-
exists
-
isDirectory
-
close
-
closeSilent
-
close
-
closeSilent
-
close
-
closeSilent
-
close
-
closeSilent
-
exception
Throw a RuntimeIOException - this function is guaranteed not to return normally -
exception
Throw a RuntimeIOException - this function is guaranteed not to return normally -
exception
Throw a RuntimeIOException - this function is guaranteed not to return normally -
flush
-
flush
-
flush
-
ensureBuffered
-
ensureBuffered
-
ensureBuffered
-
ensureBuffered
-
readWholeFile
-
readWholeFileAsUTF8
Read a whole file as UTF-8- Parameters:
filename-- Returns:
- String
-
readWholeFileAsUTF8
Read a whole stream as UTF-8- Parameters:
in- InputStream to be read- Returns:
- String
-
abbreviate
public static String abbreviate(InputStream in, Charset charset, int maxWidth, String abbrevMarker) throws IOException Fully reads the next up to maxWidth + 1 characters from the stream and returns them as a string. If the extra character is read then the apprevMarker in appended to the result in its place. Closing the stream is the caller's responsibility.- Throws:
IOException
-
abbreviate
public static String abbreviate(Reader reader, int maxWidth, String abbrevMarker) throws IOException Fully reads the next up to maxWidth + 1 characters from the reader and returns them as a string. If the extra character is read then the apprevMarker in appended to the result in its place. Closing the stream is the caller's responsibility.- Throws:
IOException
-
writeStringAsUTF8
Write a string to a file as UTF-8. The file is closed after the operation.- Parameters:
filename-content- String to be written- Throws:
IOException
-
writeStringAsUTF8
Write a string into anOutputStreamas UTF-8.- Parameters:
out- OutputStream destination.content- String to be written- Throws:
IOException
-
stringToByteBuffer
String to ByteBuffer as UTF-8 bytes -
byteBufferToString
ByteBuffer to String -
uniqueFilename
-
deleteAll
Delete everything from aPathstart point, including the path itself. This function works on files or directories. This function does not follow symbolic links. -
skipToEnd
Skip to the end of the InputStream, discarding input. -
skipToEnd
Skip to the end of the Reader, discarding input.
-