com.mucommander.io
Class BinaryDetector

java.lang.Object
  extended by com.mucommander.io.BinaryDetector

public class BinaryDetector
extends java.lang.Object

This class provides methods to determine whether some data is binary data or text data. As there is no formal characterization of what binary data really is, this method is an approximation at best and should not be trusted for anything critical.

The RECOMMENDED_BYTE_SIZE field indicates how many bytes should be provided for the detector to be confident enough.

Author:
Maxence Bernard
See Also:
EncodingDetector

Field Summary
static int RECOMMENDED_BYTE_SIZE
          Provides an indication as to the number of bytes that should fed to the detector for it to have enough confidence.
 
Constructor Summary
BinaryDetector()
           
 
Method Summary
static boolean guessBinary(byte[] b)
          This method is a shorthand for guessBinary(b, 0, b.length).
static boolean guessBinary(byte[] b, int off, int len)
          Tries and detect whether the given bytes correspond to binary or text data.
static boolean guessBinary(java.io.InputStream in)
          Tries and detect whether the given stream contains binary or text data.
This method returns true if it thinks that the bytes correspond to binary data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RECOMMENDED_BYTE_SIZE

public static final int RECOMMENDED_BYTE_SIZE
Provides an indication as to the number of bytes that should fed to the detector for it to have enough confidence.

See Also:
Constant Field Values
Constructor Detail

BinaryDetector

public BinaryDetector()
Method Detail

guessBinary

public static boolean guessBinary(byte[] b)
This method is a shorthand for guessBinary(b, 0, b.length).

Parameters:
b - the data to analyze
Returns:
true if BinaryDetector thinks that the specified data is binary

guessBinary

public static boolean guessBinary(byte[] b,
                                  int off,
                                  int len)
Tries and detect whether the given bytes correspond to binary or text data. The specified bytes can typically be the beginning of a file.
This method returns true if it thinks that the bytes correspond to binary data.

Parameters:
b - the data to analyze
off - specifies where to start reading the array
len - specifies where to stop reading the array
Returns:
true if BinaryDetector thinks that the specified data is binary

guessBinary

public static boolean guessBinary(java.io.InputStream in)
                           throws java.io.IOException
Tries and detect whether the given stream contains binary or text data.
This method returns true if it thinks that the bytes correspond to binary data.

A maximum of RECOMMENDED_BYTE_SIZE will be read from the InputStream. The stream will not be closed and will not be repositionned after the bytes have been read. It is up to the calling method to use the InputStream#mark() and InputStream#reset() methods (if supported) or reopen the stream if needed.

Parameters:
in - the stream to analyze
Returns:
true if BinaryDetector thinks that the specified data is binary
Throws:
java.io.IOException - if an error occurred while reading the InputStream.


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard