NASA World Wind

gov.nasa.worldwind.util
Class WWIO

java.lang.Object
  extended by gov.nasa.worldwind.util.WWIO

public class WWIO
extends Object


Field Summary
static String ILLEGAL_FILE_PATH_PART_CHARACTERS
           
 
Constructor Summary
WWIO()
           
 
Method Summary
static void closeStream(Object stream, String name)
          Close a stream and catch any IOException generated in the process.
static Proxy configureProxy()
           
static void copyDirectory(File source, File destination, boolean copySubDirectories)
           
static void copyFile(File source, File destination)
           
static void deleteDirectory(File file)
           
static String formPath(String... pathParts)
           
static Object getFileOrResourceAsStream(String path, Class c)
           
static InputStream getInputStreamFromByteBuffer(ByteBuffer buffer)
          Creates an InputStream for the contents of a ByteBuffer.
static InputStream getInputStreamFromString(String string)
          Creates an InputStream for the contents of a String.
static String getSuffix(String filePath)
           
static boolean isAncestorOf(File file, File ancestor)
           
static boolean isFileOutOfDate(URL url, long expiryTime)
           
static String makeSuffixForMimeType(String mimeType)
           
static MappedByteBuffer mapFile(File file)
           
static InputStream openFileOrResourceStream(String fileName, Class c)
          Opens a file located via an absolute path or a path relative to the classpath.
static ByteBuffer readFileToBuffer(File file)
           
static ByteBuffer readStreamToBuffer(InputStream inputStream)
           
static String readTextFile(File file)
          Open and read a text file into String.
static ByteBuffer readURLContentToBuffer(URL url)
           
static ByteBuffer readZipEntryToBuffer(File zipFile, String entryName)
           
static String replaceSuffix(String in, String newSuffix)
           
static boolean saveBuffer(ByteBuffer buffer, File file)
           
static boolean saveBuffer(ByteBuffer buffer, File file, boolean forceFilesystemWrite)
           
static File saveBufferToTempFile(ByteBuffer buffer, String suffix)
           
static String stripIllegalFileNameCharacters(String s)
           
static String stripLeadingSeparator(String s)
           
static String stripLeadingZeros(String s)
           
static String stripTrailingSeparator(String s)
           
static void writeTextFile(String text, File file)
          Save a String to a text file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ILLEGAL_FILE_PATH_PART_CHARACTERS

public static final String ILLEGAL_FILE_PATH_PART_CHARACTERS
See Also:
Constant Field Values
Constructor Detail

WWIO

public WWIO()
Method Detail

closeStream

public static void closeStream(Object stream,
                               String name)
Close a stream and catch any IOException generated in the process. Stream types supported are InputStream, OutputStream, Reader and Writer.

Parameters:
stream - the stream to close. If null, this method does nothing.
name - the name of the stream to place in the log message if an exception is encountered.

configureProxy

public static Proxy configureProxy()

copyDirectory

public static void copyDirectory(File source,
                                 File destination,
                                 boolean copySubDirectories)
                          throws IOException
Throws:
IOException

copyFile

public static void copyFile(File source,
                            File destination)
                     throws IOException
Throws:
IOException

deleteDirectory

public static void deleteDirectory(File file)
                            throws IOException
Throws:
IOException

formPath

public static String formPath(String... pathParts)

getFileOrResourceAsStream

public static Object getFileOrResourceAsStream(String path,
                                               Class c)

getInputStreamFromByteBuffer

public static InputStream getInputStreamFromByteBuffer(ByteBuffer buffer)
Creates an InputStream for the contents of a ByteBuffer. The method creates a copy of the buffer's contents and passes a steam reference to that copy.

Parameters:
buffer - the buffer to create a stream for.
Returns:
an InputStream for the buffer's contents.
Throws:
IllegalArgumentException - if buffer is null.

getInputStreamFromString

public static InputStream getInputStreamFromString(String string)
Creates an InputStream for the contents of a String. The method creates a copy of the string's contents and passes a steam reference to that copy.

Parameters:
string - the string to create a stream for.
Returns:
an InputStream for the string's contents.
Throws:
IllegalArgumentException - if string is null.

getSuffix

public static String getSuffix(String filePath)

isAncestorOf

public static boolean isAncestorOf(File file,
                                   File ancestor)

isFileOutOfDate

public static boolean isFileOutOfDate(URL url,
                                      long expiryTime)

makeSuffixForMimeType

public static String makeSuffixForMimeType(String mimeType)

mapFile

public static MappedByteBuffer mapFile(File file)
                                throws IOException
Throws:
IOException

openFileOrResourceStream

public static InputStream openFileOrResourceStream(String fileName,
                                                   Class c)
Opens a file located via an absolute path or a path relative to the classpath.

Parameters:
fileName - the path of the file to open, either absolute or relative to the classpath.
c - the class that will be used to find a path relative to the classpath.
Returns:
an InputStream to the open file
Throws:
IllegalArgumentException - if the file name is null.
WWRuntimeException - if an exception occurs or the file can't be found. The causing exception is available via this exception's Throwable.initCause(Throwable) method.

readFileToBuffer

public static ByteBuffer readFileToBuffer(File file)
                                   throws IOException
Throws:
IOException

readStreamToBuffer

public static ByteBuffer readStreamToBuffer(InputStream inputStream)
                                     throws IOException
Throws:
IOException

readTextFile

public static String readTextFile(File file)
Open and read a text file into String.

Parameters:
file - a File reference to the file to open and read.
Returns:
a String containing the contents of the file.
Throws:
IllegalArgumentException - if the file is null.

readURLContentToBuffer

public static ByteBuffer readURLContentToBuffer(URL url)
                                         throws IOException
Throws:
IOException

readZipEntryToBuffer

public static ByteBuffer readZipEntryToBuffer(File zipFile,
                                              String entryName)
                                       throws IOException
Throws:
IOException

replaceSuffix

public static String replaceSuffix(String in,
                                   String newSuffix)

saveBuffer

public static boolean saveBuffer(ByteBuffer buffer,
                                 File file)
                          throws IOException
Throws:
IOException

saveBuffer

public static boolean saveBuffer(ByteBuffer buffer,
                                 File file,
                                 boolean forceFilesystemWrite)
                          throws IOException
Throws:
IOException

saveBufferToTempFile

public static File saveBufferToTempFile(ByteBuffer buffer,
                                        String suffix)
                                 throws IOException
Throws:
IOException

stripIllegalFileNameCharacters

public static String stripIllegalFileNameCharacters(String s)

stripLeadingSeparator

public static String stripLeadingSeparator(String s)

stripLeadingZeros

public static String stripLeadingZeros(String s)

stripTrailingSeparator

public static String stripTrailingSeparator(String s)

writeTextFile

public static void writeTextFile(String text,
                                 File file)
Save a String to a text file.

Parameters:
text - the String to write to the file.
file - a File reference to the file to create.
Throws:
IllegalArgumentException - if the text string or file is null.

NASA World Wind