jsky.util
Class FileUtil

java.lang.Object
  extended by jsky.util.FileUtil

public class FileUtil
extends Object

Contains static utility methods for dealing with files and URLs.


Constructor Summary
FileUtil()
           
 
Method Summary
static void copy(InputStream in, OutputStream out)
          Copy the given input stream to the given output stream.
static String getSuffix(String filename)
          Return the suffix of a file.
static String getURL(URL url)
          Return the contents of the URL as a String
static void main(String[] args)
          test main
static URL makeURL(URL context, String fileOrUrlStr)
          Given a URL context (for resolving relative path names) and a string, which may be either a file or a URL string, return a new URL made from the string.
static InputStream makeURLStream(URL url)
          This method returns an InputStream for the given URL, and also wraps it in a BufferedInputStream, if necessary.
static InputStream makeURLStream(URL context, String fileOrUrlStr)
          Given a URL context (for resolving relative path names) and a string, which may be either a file or a URL string, return a new InputStream by creating the URL and opening it for reading.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

makeURL

public static URL makeURL(URL context,
                          String fileOrUrlStr)
Given a URL context (for resolving relative path names) and a string, which may be either a file or a URL string, return a new URL made from the string.

Parameters:
context - the base URL, used to resolve relative path names (may be null)
fileOrUrlStr - a file name or URL string (may be relative)

makeURLStream

public static InputStream makeURLStream(URL url)
This method returns an InputStream for the given URL, and also wraps it in a BufferedInputStream, if necessary.

Parameters:
url - the URL to read

makeURLStream

public static InputStream makeURLStream(URL context,
                                        String fileOrUrlStr)
Given a URL context (for resolving relative path names) and a string, which may be either a file or a URL string, return a new InputStream by creating the URL and opening it for reading.

Parameters:
context - the base URL, used to resolve relative path names
fileOrUrlStr - a file name or URL string (may be relative)

copy

public static void copy(InputStream in,
                        OutputStream out)
                 throws IOException
Copy the given input stream to the given output stream.

Throws:
IOException

getURL

public static String getURL(URL url)
                     throws IOException
Return the contents of the URL as a String

Throws:
IOException

getSuffix

public static String getSuffix(String filename)
Return the suffix of a file. This is everything after the first period, so can be confused by the some names with many periods not related to the suffix, for instance my.file.fits.gz.


main

public static void main(String[] args)
test main



Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.