Package javajs.util
Class Rdr
java.lang.Object
javajs.util.Rdr
- All Implemented Interfaces:
GenericLineReader
A general helper class for a variety of stream and reader functionality
including:
stream and byte magic-number decoding for PNG, PNGJ, ZIP, and GZIP streams
various stream/reader methods, including UTF-encoded stream reading
reflection-protected access to a CIF parser and ZIP tools
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
fixUTF
(byte[] bytes) static BufferedInputStream
getBIS
(byte[] bytes) static BufferedReader
static BufferedReader
getBufferedReader
(BufferedInputStream bis, String charSet) Read an input stream fully, saving a byte array, then return a buffered reader to those bytes converted to string form.static byte[]
getBytesFromSB
(SB sb) Allow for base64-encoding check.static byte[]
getLimitedStreamBytes
(InputStream is, long n) Read a possibly limited number of bytes (when n > 0) from a stream, leaving the stream open.static byte[]
getMagic
(InputStream is, int n) static BufferedInputStream
getPngZipStream
(BufferedInputStream bis, boolean asNewStream) Either advance a PNGJ stream to its zip file data or pull out the ZIP data bytes and create a new stream for them from which a ZIP utility can start extracting files.static Object
getStreamAsBytes
(BufferedInputStream bis, OC out) Read a an entire BufferedInputStream for its bytes, and either return them or leave them in the designated output channel.static BufferedInputStream
Drill down into a GZIP stack until no more layers.static BufferedInputStream
static String
getZipRoot
(String fileName) We define a request for zip file extraction by vertical bar: zipName|interiorFileName.static String
guessMimeTypeForBytes
(byte[] bytes) static boolean
static boolean
isBinary
(BufferedInputStream bis, int n) Just looking for non-printable characters.static boolean
isBZip2B
(byte[] bytes) static boolean
isBZip2S
(InputStream is) static boolean
isCompoundDocumentB
(byte[] bytes) static boolean
static boolean
isGzipB
(byte[] bytes) static boolean
isGzipS
(InputStream is) static boolean
isMessagePackB
(byte[] bytes) static boolean
static boolean
isPickleB
(byte[] bytes) static boolean
isPickleS
(InputStream is) static boolean
isPngZipB
(byte[] bytes) static boolean
static boolean
isTar
(BufferedInputStream bis) static boolean
isZipB
(byte[] bytes) static boolean
isZipS
(InputStream is) Check for a ZIP input stream - starting with "PKinvalid input: '<'03>invalid input: '<'04>"static boolean
readAllAsString
(BufferedReader br, int nBytesMax, boolean allowBinary, String[] data, int i) This method fills data[i] with string data from a file that may or may not be binary even though it is being read by a reader.readCifData
(GenericCifDataParser parser, BufferedReader br) static byte[]
Read an InputStream in its entirety as a byte array, closing the stream.static String
Read an InputStream in its entirety as a string, closing the stream.static String
Read a UTF-8 stream fully, converting it to a String.
-
Constructor Details
-
Rdr
-
-
Method Details
-
readNextLine
- Specified by:
readNextLine
in interfaceGenericLineReader
- Throws:
Exception
-
readCifData
-
fixUTF
-
isBase64
-
isCompoundDocumentS
-
isCompoundDocumentB
public static boolean isCompoundDocumentB(byte[] bytes) -
isBZip2S
-
isGzipS
-
isBZip2B
public static boolean isBZip2B(byte[] bytes) -
isGzipB
public static boolean isGzipB(byte[] bytes) -
isPickleS
-
isPickleB
public static boolean isPickleB(byte[] bytes) -
isMessagePackS
-
isMessagePackB
public static boolean isMessagePackB(byte[] bytes) -
isPngZipStream
-
isPngZipB
public static boolean isPngZipB(byte[] bytes) -
isZipS
Check for a ZIP input stream - starting with "PKinvalid input: '<'03>invalid input: '<'04>"- Parameters:
is
-- Returns:
- true if a ZIP stream
-
isZipB
public static boolean isZipB(byte[] bytes) -
getMagic
-
guessMimeTypeForBytes
-
getBIS
-
getBR
-
getUnzippedInputStream
public static BufferedInputStream getUnzippedInputStream(GenericZipTools jzt, BufferedInputStream bis) throws IOException Drill down into a GZIP stack until no more layers.- Parameters:
jzt
-bis
-- Returns:
- non-gzipped buffered input stream.
- Throws:
IOException
-
getUnzippedInputStreamBZip2
public static BufferedInputStream getUnzippedInputStreamBZip2(GenericZipTools jzt, BufferedInputStream bis) throws IOException - Throws:
IOException
-
getBytesFromSB
Allow for base64-encoding check.- Parameters:
sb
-- Returns:
- byte array
-
getStreamAsBytes
Read a an entire BufferedInputStream for its bytes, and either return them or leave them in the designated output channel.- Parameters:
bis
-out
- a destination output channel, or null- Returns:
- byte[] (if out is null) or a message indicating length (if not)
- Throws:
IOException
-
getBufferedReader
public static BufferedReader getBufferedReader(BufferedInputStream bis, String charSet) throws IOException Read an input stream fully, saving a byte array, then return a buffered reader to those bytes converted to string form.- Parameters:
bis
-charSet
-- Returns:
- Reader
- Throws:
IOException
-
getLimitedStreamBytes
Read a possibly limited number of bytes (when n > 0) from a stream, leaving the stream open.- Parameters:
is
- an input stream, not necessarily buffered.n
- the maximum number of bytes to read, or -1 for all- Returns:
- the bytes read
- Throws:
IOException
-
streamToUTF8String
Read a UTF-8 stream fully, converting it to a String. Called by Jmol's XMLReaders- Parameters:
bis
-- Returns:
- a UTF-8 string
-
readAllAsString
public static boolean readAllAsString(BufferedReader br, int nBytesMax, boolean allowBinary, String[] data, int i) This method fills data[i] with string data from a file that may or may not be binary even though it is being read by a reader. It is meant to be used simple text-based files only.- Parameters:
br
-nBytesMax
-allowBinary
-data
-i
-- Returns:
- true if data[i] holds the data; false if data[i] holds an error message.
-
getPngZipStream
Either advance a PNGJ stream to its zip file data or pull out the ZIP data bytes and create a new stream for them from which a ZIP utility can start extracting files.- Parameters:
bis
-asNewStream
-- Returns:
- new buffered ByteArrayInputStream, possibly with no data if there is an error
-
getZipRoot
We define a request for zip file extraction by vertical bar: zipName|interiorFileName. These may be nested if there is a zip file contained in a zip file.- Parameters:
fileName
-- Returns:
- filename trimmed of interior fileName
-
isTar
-
streamToBytes
Read an InputStream in its entirety as a byte array, closing the stream.- Parameters:
is
-- Returns:
- a byte array
- Throws:
IOException
-
streamToString
Read an InputStream in its entirety as a string, closing the stream.- Parameters:
is
-- Returns:
- a String
- Throws:
IOException
-
isBinary
Just looking for non-printable characters.- Parameters:
bis
-n
- length to scan- Returns:
- true if non-printable characters found
-