## org.das2.util.FileUtil

static utility methods. introduced Jul 28, 2008.

## consumeStream

consumeStream( java.io.InputStream in ) → int

read all the bytes off the stream, perhaps to empty a URL response. This does not close the stream!

### Parameters

in - the input stream, which will not be closed by this method.

### Returns:

the total number of bytes read.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## deleteFileTree

deleteFileTree( java.io.File root ) → boolean

deletes all files and folders below root, and root, just as "rm -r" would. TODO: check links

### Parameters

root - the root where we start deleting.

### Returns:

true if the operation was successful.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## deleteFileTree

deleteFileTree( java.io.File root, java.util.Set exclude ) → boolean

deletes all files and folders below root, and root, just as "rm -r" would, excluding any files named in exclude. For example, exclude could contain "readme.txt".

### Parameters

root - the root where we start deleting.
exclude - null or a set containing names to exclude.

### Returns:

true if the operation was successful.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## deleteWithinFileTree

deleteWithinFileTree( java.io.File root, String name ) → boolean

deletes all files with the given name, and root, just as "find . -name name -exec rm {} \;" would. TODO: check links. For example deleteWithinFileTree( root, ".listing" )

### Parameters

root - the root directory of the tree.
name - the file name.

### Returns:

true if the operation was successful.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## fileCompare

fileCompare( java.io.File file1, java.io.File file2 ) → boolean

returns True if the file contents are equal.

### Parameters

file1 - a File
file2 - a File

### Returns:

true if the two files have identical
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## fileCopy

fileCopy( java.io.File src, java.io.File dst ) → void

copies the file or folder from src to dst.

### Parameters

src - the source file or folder.
dst - the location for the new file or folder.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## find

find( java.io.File root, String name ) → java.io.File

find a files with the given name within the given root, just as "find . -name name -print \;" would. TODO: check links. For example, find( "/usr/share/fonts/truetype", "FreeMono.ttf" )

### Parameters

root - the root to start
name - name to look for.

### Returns:

the File found, or null if it does not exist.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## find

find( java.io.File root, java.util.regex.Pattern pattern, java.util.List result ) → int

find a files with the given pattern within the given root, just as "find . -name *.dat -print \;" would. TODO: check links. For example, find( "/usr/share/fonts/truetype", "FreeMono.ttf" )

### Parameters

root - the root to start
pattern - name to look for.
result - results are added to this list, or null if the count that is all that is needed.

### Returns:

the number of files found

### See Also:

org.das2.util.filesystem.Glob
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## find

find( java.io.File[] roots, String name ) → java.io.File

find a files with the given name within one of the given roots. TODO: check links. For example, find( "/usr/share/fonts/truetype", "FreeMono.ttf" ) This allows root folders that do not exist.

### Parameters

roots - array of roots to start search.
name - name to look for.

### Returns:

the File found, or null if it does not exist.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getMagic

getMagic( java.io.File src ) → String

return the first four bytes of the file as a string. Some magic numbers we care about:

- '\x89HDF' HDF (and new NetCDF) files

  ### Parameters

  src - a File

  ### Returns:

  a four byte string
  [search for examples] [view on GitHub] [view on old javadoc] [view source]

  ## isParent

  isParent( java.io.File possibleParent, java.io.File maybeChild ) → boolean

  return true of the maybeChild parent is a child of possibleParent. Note either can be null, and this will not throw an exception, but will return false.

  ### Parameters

  possibleParent - parent file.
  maybeChild - a file or folder which may exist within possibleParent.

  ### Returns:

  true if the possibleParent is actually a parent of maybeChild.
  [search for examples] [view on GitHub] [view on old javadoc] [view source]

  ## lineCount

  lineCount( java.io.File f ) → int

  return the number of lines in the text file. Breaking the file into lines is handled by Java's BufferedReader.

  ### Parameters

  f - the file

  ### Returns:

  the number of lines.

  ### See Also:

  BufferedReader
  [search for examples] [view on GitHub] [view on old javadoc] [view source]

  ## listRecursively

  listRecursively( java.io.File root, java.util.regex.Pattern name, java.util.List matches ) → java.util.List

  find all files under the root matching the spec.

  ### Parameters

  root - the root of the search (e.g. /fonts/)
  name - the pattern to match
  matches - list that will accept the matches, or null if one should be created.

  ### Returns:

  the list.
  [search for examples] [view on GitHub] [view on old javadoc] [view source]

  ## listRecursively

  listRecursively( java.io.File root, String glob ) → java.io.File[]

  Return an array of files where the regex is found at the end. A check is performed to see if the root is case-insensitive.

  ### Parameters

  root - the root of the search (e.g. /fonts/)
  glob - the glob to match (e.g. *.ttf)

  ### Returns:

  list of files.
  [search for examples] [view on GitHub] [view on old javadoc] [view source]

  ## readFileToString

  readFileToString( java.io.File f ) → String

  read all the bytes in the UTF-8 encoded file into a string.

  ### Parameters

  f - the file, which presumed to be UTF-8 (or ASCII) encoded.

  ### Returns:

  string containing the contents of the file.
  [search for examples] [view on GitHub] [view on old javadoc] [view source]

  ## readInputStreamToString

  readInputStreamToString( java.io.InputStream ins ) → String

  read all the bytes in the UTF-8 encoded inputStream into a string.

  ### Parameters

  ins - the input stream

  ### Returns:

  string containing the contents of the file.
  [search for examples] [view on GitHub] [view on old javadoc] [view source]

  ## writeStringToFile

  writeStringToFile( java.io.File f, String src ) → void

  write all the bytes in the string to a file using UTF-8 encoding.

  ### Parameters

  f - the file name.
  src - the string to write to the file.

  ### Returns:

  void (returns nothing)
  [search for examples] [view on GitHub] [view on old javadoc] [view source]