java.lang.Object
org.apache.jena.atlas.io.IO

public class IO extends Object
  • Field Details

  • Constructor Details

    • IO

      public IO()
  • Method Details

    • openFile

      public static InputStream openFile(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 RuntimeIOException on failure to open.

    • openFileBuffered

      public static InputStream openFileBuffered(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 this InputStream with an InputStreamReader (e.g. to get UTF-8), there is no need to buffer the InputStream. Instead, buffer the Reader.

      Throws RuntimeIOException on failure to open.

    • openFileEx

      public static InputStream openFileEx(String filename) throws IOException, FileNotFoundException
      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:
      FileNotFoundException
      IOException
    • filenameNoCompression

      public static String filenameNoCompression(String filename)
      The filename without any compression extension, or the original filename. It tests for compression types handled by openFileEx(java.lang.String).
    • openFileUTF8

      public static Reader openFileUTF8(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 Reader openFileASCII(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 Reader asUTF8(InputStream in)
      Create an unbuffered reader that uses UTF-8 encoding
    • asASCII

      public static Reader asASCII(InputStream in)
      Create a unbuffered reader that uses ASCII encoding
    • asBufferedUTF8

      public static BufferedReader asBufferedUTF8(InputStream in)
      Create an buffered reader that uses UTF-8 encoding
    • asUTF8

      public static Writer asUTF8(OutputStream out)
      Create a writer that uses UTF-8 encoding
    • asASCII

      public static Writer asASCII(OutputStream out)
      Create a writer that uses ASCII encoding
    • asBufferedUTF8

      public static Writer asBufferedUTF8(OutputStream out)
      Create a writer that uses UTF-8 encoding and is buffered.
    • openOutputFile

      public static OutputStream openOutputFile(String filename)
      Open a file for output - may include adding gzip processing.

      Throws RuntimeIOException on 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
    • sink

      public static OutputStream sink()
      An OutputStream that discards all bytes.
    • wrap

      public static AWriter wrap(Writer w)
      Wrap in a general writer interface
    • wrapUTF8

      public static AWriter wrapUTF8(OutputStream out)
      Wrap in a general writer interface
    • wrapASCII

      public static AWriter wrapASCII(OutputStream out)
      Wrap in a general writer interface
    • asPrintWriterUTF8

      public static PrintWriter asPrintWriterUTF8(OutputStream out)
      Create a print writer that uses UTF-8 encoding
    • isEmptyDirectory

      public static boolean isEmptyDirectory(String directory)
    • exists

      public static boolean exists(String fsname)
    • isDirectory

      public static boolean isDirectory(String directory)
    • close

      public static void close(Closeable resource)
    • closeSilent

      public static void closeSilent(Closeable resource)
    • close

      public static void close(Closeable resource)
    • closeSilent

      public static void closeSilent(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(String message)
      Throw a RuntimeIOException - this function is guaranteed not to return normally
    • exception

      public static void exception(IOException ex)
      Throw a RuntimeIOException - this function is guaranteed not to return normally
    • exception

      public static void exception(String msg, IOException ex)
      Throw a RuntimeIOException - this function is guaranteed not to return normally
    • flush

      public static void flush(OutputStream out)
    • flush

      public static void flush(Writer out)
    • flush

      public static void flush(AWriter out)
    • ensureBuffered

      public static InputStream ensureBuffered(InputStream input)
    • ensureBuffered

      public static Reader ensureBuffered(Reader input)
    • ensureBuffered

      public static OutputStream ensureBuffered(OutputStream output)
    • ensureBuffered

      public static Writer ensureBuffered(Writer output)
    • readWholeFile

      public static byte[] readWholeFile(InputStream in)
    • readWholeFileAsUTF8

      public static String readWholeFileAsUTF8(String filename)
      Read a whole file as UTF-8
      Parameters:
      filename -
      Returns:
      String
    • readWholeFileAsUTF8

      public static String readWholeFileAsUTF8(InputStream in)
      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

      public static void writeStringAsUTF8(String filename, String content) throws IOException
      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

      public static void writeStringAsUTF8(OutputStream out, String content) throws IOException
      Write a string into an OutputStream as UTF-8.
      Parameters:
      out - OutputStream destination.
      content - String to be written
      Throws:
      IOException
    • stringToByteBuffer

      public static ByteBuffer stringToByteBuffer(String str)
      String to ByteBuffer as UTF-8 bytes
    • byteBufferToString

      public static String byteBufferToString(ByteBuffer bb)
      ByteBuffer to String
    • uniqueFilename

      public static String uniqueFilename(String directory, String base, String ext)
    • deleteAll

      public static void deleteAll(Path start)
      Delete everything from a Path start point, including the path itself. This function works on files or directories. This function does not follow symbolic links.
    • skipToEnd

      public static void skipToEnd(InputStream input)
      Skip to the end of the InputStream, discarding input.
    • skipToEnd

      public static void skipToEnd(Reader input)
      Skip to the end of the Reader, discarding input.