# Class Rdr

java.lang.Object
javajs.util.Rdr

All Implemented Interfaces:
  `GenericLineReader`

public class Rdr extends Object implements 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
Modifier and Type
Class
Description
`static class`
`Rdr.StreamReader`

## Constructor Summary

Constructors
Constructor
Description
`Rdr(BufferedReader reader)`

## Method Summary

Modifier and Type
Method
Description
`static String`
`fixUTF(byte[] bytes)`
////////
`static BufferedInputStream`
`getBIS(byte[] bytes)`
/////// stream/byte methods ///////////
`static BufferedReader`
`getBR(String string)`
`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`
`getUnzippedInputStream(GenericZipTools jzt, BufferedInputStream bis)`
Drill down into a GZIP stack until no more layers.
`static BufferedInputStream`
`getUnzippedInputStreamBZip2(GenericZipTools jzt, BufferedInputStream bis)`
`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`
`isBase64(SB sb)`
`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`
`isCompoundDocumentS(InputStream is)`
`static boolean`
`isGzipB(byte[] bytes)`
`static boolean`
`isGzipS(InputStream is)`
`static boolean`
`isMessagePackB(byte[] bytes)`
`static boolean`
`isMessagePackS(InputStream is)`
`static boolean`
`isPickleB(byte[] bytes)`
`static boolean`
`isPickleS(InputStream is)`
`static boolean`
`isPngZipB(byte[] bytes)`
`static boolean`
`isPngZipStream(InputStream is)`
`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.
`static Map<String,Object>`
`readCifData(GenericCifDataParser parser, BufferedReader br, String[] keys)`
`String`
`readNextLine()`
`static byte[]`
`streamToBytes(InputStream is)`
Read an InputStream in its entirety as a byte array, closing the stream.
`static String`
`streamToString(InputStream is)`
Read an InputStream in its entirety as a string, closing the stream.
`static String`
`streamToUTF8String(BufferedInputStream bis)`
Read a UTF-8 stream fully, converting it to a String.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### Rdr

public Rdr(BufferedReader reader)

## Method Details

### readNextLine

public String readNextLine() throws Exception

Specified by:
  `readNextLine` in interface `GenericLineReader`
Throws:
  `Exception`

### readCifData

public static Map<String,Object> readCifData(GenericCifDataParser parser, BufferedReader br, String[] keys)

### fixUTF

public static String fixUTF(byte[] bytes)
////////

### isBase64

public static boolean isBase64(SB sb)

### isCompoundDocumentS

public static boolean isCompoundDocumentS(InputStream is)

### isCompoundDocumentB

public static boolean isCompoundDocumentB(byte[] bytes)

### isBZip2S

public static boolean isBZip2S(InputStream is)

### isGzipS

public static boolean isGzipS(InputStream is)

### isBZip2B

public static boolean isBZip2B(byte[] bytes)

### isGzipB

public static boolean isGzipB(byte[] bytes)

### isPickleS

public static boolean isPickleS(InputStream is)

### isPickleB

public static boolean isPickleB(byte[] bytes)

### isMessagePackS

public static boolean isMessagePackS(InputStream is)

### isMessagePackB

public static boolean isMessagePackB(byte[] bytes)

### isPngZipStream

public static boolean isPngZipStream(InputStream is)

### isPngZipB

public static boolean isPngZipB(byte[] bytes)

### isZipS

public static boolean isZipS(InputStream is)
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

public static byte[] getMagic(InputStream is, int n)

### guessMimeTypeForBytes

public static String guessMimeTypeForBytes(byte[] bytes)

### getBIS

public static BufferedInputStream getBIS(byte[] bytes)
/////// stream/byte methods ///////////

### getBR

public static BufferedReader getBR(String string)

### 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

public static byte[] getBytesFromSB(SB sb)
Allow for base64-encoding check.

Parameters:
  `sb` -
Returns:
  byte array

### getStreamAsBytes

public static Object getStreamAsBytes(BufferedInputStream bis, OC out) throws IOException
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

public static byte[] getLimitedStreamBytes(InputStream is, long n) throws IOException
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

public static String streamToUTF8String(BufferedInputStream bis)
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

public 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.

Parameters:
  `bis` -
  `asNewStream` -
Returns:
  new buffered ByteArrayInputStream, possibly with no data if there is an error

### getZipRoot

public static String getZipRoot(String fileName)
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

public static boolean isTar(BufferedInputStream bis)

### streamToBytes

public static byte[] streamToBytes(InputStream is) throws IOException
Read an InputStream in its entirety as a byte array, closing the stream.

Parameters:
  `is` -
Returns:
  a byte array
Throws:
  `IOException`

### streamToString

public static String streamToString(InputStream is) throws IOException
Read an InputStream in its entirety as a string, closing the stream.

Parameters:
  `is` -
Returns:
  a String
Throws:
  `IOException`

### isBinary

public static boolean isBinary(BufferedInputStream bis, int n)
Just looking for non-printable characters.

Parameters:
  `bis` -
  `n` - length to scan
Returns:
  true if non-printable characters found