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 DELETE_ON_EXIT_PREFIX
           
static String ILLEGAL_FILE_PATH_PART_CHARACTERS
           
 
Constructor Summary
WWIO()
           
 
Method Summary
static String byteBufferToString(ByteBuffer buffer, String encoding)
          Create a String from a ByteBuffer.
static void closeStream(Object stream, String name)
          Close a stream and catch any IOException generated in the process.
static Proxy configureProxy()
           
static File convertURLToFile(URL url)
          Converts a specified URL as to a path in the local file system.
static void copyDirectory(File source, File destination, boolean copySubDirectories)
           
static void copyFile(File source, File destination)
           
static void deflateBufferToFile(ByteBuffer buffer, File file)
           
static void deleteDirectory(File file)
           
static String formPath(String... pathParts)
           
static String getFilename(String filePath)
          Returns the name of the file or directory denoted by the specified path.
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 getParentFilePath(String filePath)
          Returns the file path's parent directory path, or null if the file path does not have a parent.
static String getSuffix(String filePath)
           
static ByteBuffer inflateFileToBuffer(File file)
           
static ByteBuffer inflateStreamToBuffer(InputStream inputStream)
           
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 boolean saveBufferToStream(ByteBuffer buffer, OutputStream fos)
           
static File saveBufferToTempFile(ByteBuffer buffer, String suffix)
           
static ByteBuffer stringToByteBuffer(String string, String encoding)
          Create a ByteBuffer from a String.
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

DELETE_ON_EXIT_PREFIX

public static final String DELETE_ON_EXIT_PREFIX
See Also:
Constant Field Values

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

byteBufferToString

public static String byteBufferToString(ByteBuffer buffer,
                                        String encoding)
Create a String from a ByteBuffer.

Parameters:
buffer - the byte buffer to convert.
encoding - the encoding do use. If null is specified then UTF-8 is used.
Returns:
the string representation of the bytes in the buffer decoded according to the specified encoding.

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()

convertURLToFile

public static File convertURLToFile(URL url)
Converts a specified URL as to a path in the local file system. If the URL cannot be converted to a file path for any reason, this returns null.

Parameters:
url - the URL to convert to a local file path.
Returns:
a local File path, or null if the URL could not be converted.
Throws:
IllegalArgumentException - if the url is null.

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

deflateBufferToFile

public static void deflateBufferToFile(ByteBuffer buffer,
                                       File file)
                                throws IOException
Throws:
IOException

deleteDirectory

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

formPath

public static String formPath(String... pathParts)

getFilename

public static String getFilename(String filePath)
Returns the name of the file or directory denoted by the specified path. This is the last file name in the path, or null if the path does not contain any file names.

Parameters:
filePath - a file path String.
Returns:
the last name in the specified path, or null if the path does not contain a name.
Throws:
IllegalArgumentException - if the file path is null.

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.

getParentFilePath

public static String getParentFilePath(String filePath)
Returns the file path's parent directory path, or null if the file path does not have a parent.

Parameters:
filePath - a file path String.
Returns:
the file path's parent directory, or null if the path does not have a parent.
Throws:
IllegalArgumentException - if the file path is null.

getSuffix

public static String getSuffix(String filePath)

inflateFileToBuffer

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

inflateStreamToBuffer

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

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

saveBufferToStream

public static boolean saveBufferToStream(ByteBuffer buffer,
                                         OutputStream fos)
                                  throws IOException
Throws:
IOException

saveBufferToTempFile

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

stringToByteBuffer

public static ByteBuffer stringToByteBuffer(String string,
                                            String encoding)
                                     throws UnsupportedEncodingException
Create a ByteBuffer from a String.

Parameters:
string - the string to convert.
encoding - the encoding do use. If null is specified then UTF-8 is used.
Returns:
the ByteBuffer representation of the string decoded according to the specified encoding.
Throws:
UnsupportedEncodingException - if the specified encoding is not supported

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

Hosted by docs.bugaco.com