Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

io



The io package contains additional classes which work with the Java io package.

FileUtilities

Main Article: FileUtilities

The FileUtilities class contains many utility methods to deals with Files and URLs. The FileUtilities2 class contains also some additional utility methods.

FileFilter

The ExtensionFilenameFilter class is both a simple FilenameFilter and FileFilter implementation, allowing to use it in both JFileChooser or directories listings.

Example:
   String[] ext = {"jpg","jpeg","tiff","png","svg"};
   ExtensionFilenameFilter graphicfilter = new ExtensionFileFilter(ext,"JPEG,PNG,TIFF,SVG images");

StreamGobbler

Main Article: StreamGobbler

The StreamGobbler class constantly consumes the input from an InputStream, and distribute the input lines to a listener. This is often useful when using ProcessBuilder and listen to the InputStream coming from the external process..

Contrary to many implementations seen on the Web, this class defer the actual work to a listener.

For example the following code will redirect the output of an executable (normally on the console) to a List of Strings:
   ProcessBuilder pb = new ProcessBuilder("my_executable.exe");
   Process process = pb.start();
      
   StreamGobbler outgobbler = new StreamGobbler(process.getInputStream());
   List<String> lines = new ArrayList<>
   outgobbler.setListener(new StreamGobbler.Listener() {
      @Override
      public void readLine(String line) {
         lines.add(line);
      }

      @Override
      public void close() {
      }
   });
   errorgobbler.start();
   outgobbler.start();

SocketUtilities

The SocketUtilities class contains two utility methods to get free ports.

See also


Categories: Io | Packages

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences