Package javajs.util

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
  • Constructor Details

  • 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)
    • 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)
    • 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