no.sintef.file
Class IOUtils

java.lang.Object
  extended byno.sintef.file.IOUtils

public final class IOUtils
extends java.lang.Object

IO utility class.

Author:
Fredrik Vraalsen

Method Summary
static java.io.File getDefaultDir()
          Get current default directory.
static javax.swing.filechooser.FileFilter[] mergeFilters(javax.swing.filechooser.FileFilter[] f1, javax.swing.filechooser.FileFilter[] f2)
          Merge two FileFilter arrays.
static byte[] readFully(java.io.File file)
          Read complete File contents into byte array.
static byte[] readFully(java.io.InputStream is)
          Read contents of InputStream into byte array.
static byte[] readFully(java.net.URL url)
          Read contents of URL into byte array.
static void saveFile(byte[] bytes, java.io.File file)
          Save contents of byte array to the specified file.
static void setDefaultDir(java.io.File dir)
          Set current default directory.
static java.io.File showOpenDialog(java.lang.String defaultFilename, javax.swing.filechooser.FileFilter[] filters, java.awt.Component parent)
          Show file dialog to ask user to select a file to open.
static java.io.File showSaveDialog(java.lang.String defaultFilename, java.awt.Component parent)
          Show file dialog requesting user to choose file to save to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDefaultDir

public static java.io.File getDefaultDir()
Get current default directory.

Returns:
current default directory

setDefaultDir

public static void setDefaultDir(java.io.File dir)
Set current default directory.

Parameters:
dir - new current default directory.

readFully

public static byte[] readFully(java.io.File file)
                        throws java.io.IOException
Read complete File contents into byte array.

Parameters:
file - File to read from
Returns:
byte array of File contents
Throws:
java.io.IOException - if IO error occurs

readFully

public static byte[] readFully(java.net.URL url)
                        throws java.io.IOException
Read contents of URL into byte array.

Parameters:
url - URL to read from
Returns:
byte array of URL contents
Throws:
java.io.IOException - if IO error occurs

readFully

public static byte[] readFully(java.io.InputStream is)
                        throws java.io.IOException
Read contents of InputStream into byte array.

Parameters:
is - InputStream to read from
Returns:
byte array of InputStream contents
Throws:
java.io.IOException - if IO error occurs

saveFile

public static void saveFile(byte[] bytes,
                            java.io.File file)
                     throws java.io.IOException
Save contents of byte array to the specified file.

Parameters:
bytes - byte array with contents to save
file - file to save to
Throws:
java.io.IOException - if IO error occurs

showSaveDialog

public static java.io.File showSaveDialog(java.lang.String defaultFilename,
                                          java.awt.Component parent)
Show file dialog requesting user to choose file to save to.

Parameters:
defaultFilename - default file name for dialog
parent - parent Component to align the dialog to
Returns:
File to save contents to, or null if cancelled or file not writable

showOpenDialog

public static java.io.File showOpenDialog(java.lang.String defaultFilename,
                                          javax.swing.filechooser.FileFilter[] filters,
                                          java.awt.Component parent)
Show file dialog to ask user to select a file to open.

Parameters:
defaultFilename - default file name for dialog
filters - array of filename filters
parent - parent Component to align the dialog to
Returns:
File to open

mergeFilters

public static javax.swing.filechooser.FileFilter[] mergeFilters(javax.swing.filechooser.FileFilter[] f1,
                                                                javax.swing.filechooser.FileFilter[] f2)
Merge two FileFilter arrays.

Parameters:
f1 - the first FileFilter array
f2 - the second FileFilter array
Returns:
the merged FileFilters


Copyright © 2003-2005 SINTEF. All Rights Reserved.