Module jEdit

Class IOUtilities

java.lang.Object
org.gjt.sp.util.IOUtilities

public class IOUtilities extends Object
IO tools that depend on JDK only.
Since:
4.3pre5
Version:
$Id: IOUtilities.java 25273 2020-04-19 16:29:30Z kpouer $
Author:
Matthieu Casanova
  • Method Details

    • moveFile

      public static boolean moveFile(File source, File dest)
      Moves the source file to the destination. If the destination cannot be created or is a read-only file, the method returns false. Otherwise, the contents of the source are copied to the destination, the source is deleted, and true is returned.
      Parameters:
      source - The source file to move.
      dest - The destination where to move the file.
      Returns:
      true on success, false otherwise.
      Since:
      jEdit 4.3pre9
    • copyStream

      public static boolean copyStream(int bufferSize, @Nullable ProgressObserver progress, String progressPrefix, InputStream in, OutputStream out, boolean canStop) throws IOException
      Copy an input stream to an output stream.
      Parameters:
      bufferSize - the size of the buffer
      progress - the progress observer it could be null
      progressPrefix - the progress prefix, it could be null
      in - the input stream
      out - the output stream
      canStop - if true, the copy can be stopped by interrupting the thread
      Returns:
      true if the copy was done, false if it was interrupted
      Throws:
      IOException - IOException If an I/O error occurs
    • copyStream

      public static boolean copyStream(int bufferSize, @Nullable ProgressObserver progress, InputStream in, OutputStream out, boolean canStop) throws IOException
      Copy an input stream to an output stream.
      Parameters:
      bufferSize - the size of the buffer
      progress - the progress observer it could be null
      in - the input stream
      out - the output stream
      canStop - if true, the copy can be stopped by interrupting the thread
      Returns:
      true if the copy was done, false if it was interrupted
      Throws:
      IOException - IOException If an I/O error occurs
    • copyStream

      public static boolean copyStream(@Nullable ProgressObserver progress, InputStream in, OutputStream out, boolean canStop) throws IOException
      Copy an input stream to an output stream with a buffer of 4096 bytes.
      Parameters:
      progress - the progress observer it could be null
      in - the input stream
      out - the output stream
      canStop - if true, the copy can be stopped by interrupting the thread
      Returns:
      true if the copy was done, false if it was interrupted
      Throws:
      IOException - IOException If an I/O error occurs
    • copyStream

      public static boolean copyStream(@Nullable ProgressObserver progress, String progressPrefix, InputStream in, OutputStream out, boolean canStop) throws IOException
      Copy an input stream to an output stream with a buffer of 4096 bytes.
      Parameters:
      progress - the progress observer it could be null
      progressPrefix - the progress prefix, it could be null
      in - the input stream
      out - the output stream
      canStop - if true, the copy can be stopped by interrupting the thread
      Returns:
      true if the copy was done, false if it was interrupted
      Throws:
      IOException - IOException If an I/O error occurs
    • toByteArray

      public static byte[] toByteArray(InputStream in) throws IOException
      Convert an InputStream into a byte array
      Parameters:
      in - the input stream
      Throws:
      IOException - IOException If an I/O error occurs
      Since:
      jEdit 5.6pre1
    • toString

      public static String toString(InputStream in) throws IOException
      Convert an InputStream into a String with UTF-8 encoding
      Parameters:
      in - the input stream
      Throws:
      IOException - IOException If an I/O error occurs
      Since:
      jEdit 5.6pre1
    • toString

      public static String toString(InputStream in, Charset charset) throws IOException
      Convert an InputStream into a String
      Parameters:
      in - the input stream
      charset - the choosend charset
      Throws:
      IOException - IOException If an I/O error occurs
      Since:
      jEdit 5.6pre1
    • fileLength

      public static long fileLength(File file)
      Returns the length of a file. If it is a directory it will calculate recursively the length.
      Parameters:
      file - the file or directory
      Returns:
      the length of the file or directory. If the file doesn't exist it will return 0
      Since:
      4.3pre10
    • closeQuietly

      public static void closeQuietly(@Nullable Closeable closeable)
      Method that will close a Closeable ignoring it if it is null and ignoring exceptions.
      Parameters:
      closeable - the closeable to close.
      Since:
      jEdit 4.3pre8
    • closeQuietly

      public void closeQuietly(@Nullable ObjectInput in)
      Method that will close an ObjectInput ignoring it if it is null and ignoring exceptions.
      Parameters:
      in - the closeable to close.
      Since:
      jEdit 5.1pre1
    • closeQuietly

      public void closeQuietly(@Nullable ObjectOutput out)
      Method that will close an ObjectOutput ignoring it if it is null and ignoring exceptions.
      Parameters:
      out - the closeable to close.
      Since:
      jEdit 5.1pre1