/** Read the next line of text from the input stream. */ @Override public String readLine() throws IOException { return findString("\n"); }
/** Read bytes from the stream into the given array. */ @Override public int read(byte[] array) throws IOException { return read(array, 0, array.length); }
/** Read bytes from the stream into the given array. */ @Override public void readFully(byte[] array) throws IOException { readFully(array, 0, array.length); }
long startPos = getFilePointer(); long bytesDropped = 0; long inputLen = length(); long maxLen = inputLen - startPos; boolean tooLong = saveString && maxLen > MAX_SEARCH_SIZE; seek(startPos + bytesDropped + min + tagLen);
long startPos = getFilePointer(); long bytesDropped = 0; long inputLen = length(); long maxLen = inputLen - startPos; boolean tooLong = saveString && maxLen > MAX_SEARCH_SIZE; seek(startPos + bytesDropped + min + tagLen);
/** Read a string of arbitrary length, terminated by a null char. */ public String readCString() throws IOException { return findString("\0"); }
/** Read bytes from the stream into the given array. */ @Override public void readFully(byte[] array) throws IOException { readFully(array, 0, array.length); }
/** Read bytes from the stream into the given array. */ @Override public int read(byte[] array) throws IOException { return read(array, 0, array.length); }
/** * Read a string of arbitrary length, terminated by a null char. * * @return the smallest string such that the last character is a null byte * @throws IOException if a null-terminated string is not found * @see #findString(String...) */ public String readCString() throws IOException { return findString("\0"); }
/** * Read a string of length n. * * @param n the number of bytes to read * @return a string representing the next <code>n</code> bytes in the stream * @throws IOException if there is an error during reading */ public String readString(int n) throws IOException { byte[] b = new byte[n]; readFully(b); return new String(b, Constants.ENCODING); }
/** * Reads a string ending with one of the given terminating substrings. * * @param terminators The strings for which to search. * * @return The string from the initial position through the end of the * terminating sequence, or through the end of the stream if no * terminating sequence is found. */ public String findString(String... terminators) throws IOException { return findString(true, DEFAULT_BLOCK_SIZE, terminators); }
/** Read a string of length n. */ public String readString(int n) throws IOException { byte[] b = new byte[n]; readFully(b); return new String(b, Constants.ENCODING); }
/** Read the next line of text from the input stream. */ @Override public String readLine() throws IOException { return findString("\n"); }
/** * Reads a string ending with one of the given terminating substrings. * * @param terminators The strings for which to search. * * @return The string from the initial position through the end of the * terminating sequence, or through the end of the stream if no * terminating sequence is found. * @throws IOException If the maximum search length (512 MB) is exceeded. */ public String findString(String... terminators) throws IOException { return findString(true, DEFAULT_BLOCK_SIZE, terminators); }
/** * Reads a string ending with one of the given terminating * substrings, using the specified block size for buffering. * * @param blockSize The block size to use when reading bytes in chunks. * @param terminators The strings for which to search. * * @return The string from the initial position through the end of the * terminating sequence, or through the end of the stream if no * terminating sequence is found. */ public String findString(int blockSize, String... terminators) throws IOException { return findString(true, blockSize, terminators); }
/** * Reads a string ending with one of the given terminating * substrings, using the specified block size for buffering. * * @param blockSize The block size to use when reading bytes in chunks. * @param terminators The strings for which to search. * * @return The string from the initial position through the end of the * terminating sequence, or through the end of the stream if no * terminating sequence is found. * @throws IOException If the maximum search length (512 MB) is exceeded. */ public String findString(int blockSize, String... terminators) throws IOException { return findString(true, blockSize, terminators); }
/** * Reads or skips a string ending with * one of the given terminating substrings. * * @param saveString Whether to collect the string from the current file * pointer to the terminating bytes, and return it. If false, returns null. * @param terminators The strings for which to search. * * @throws IOException If saveString flag is set * and the maximum search length (512 MB) is exceeded. * * @return The string from the initial position through the end of the * terminating sequence, or through the end of the stream if no * terminating sequence is found, or null if saveString flag is unset. */ public String findString(boolean saveString, String... terminators) throws IOException { return findString(saveString, DEFAULT_BLOCK_SIZE, terminators); }
/** * Reads or skips a string ending with * one of the given terminating substrings. * * @param saveString Whether to collect the string from the current file * pointer to the terminating bytes, and return it. If false, returns null. * @param terminators The strings for which to search. * * @throws IOException If saveString flag is set * and the maximum search length (512 MB) is exceeded. * * @return The string from the initial position through the end of the * terminating sequence, or through the end of the stream if no * terminating sequence is found, or null if saveString flag is unset. * @throws IOException If saveString flag is set * and the maximum search length (512 MB) is exceeded. */ public String findString(boolean saveString, String... terminators) throws IOException { return findString(saveString, DEFAULT_BLOCK_SIZE, terminators); }
/** * Reads a string ending with one of the characters in the given string. * * @see #findString(String...) */ public String readString(String lastChars) throws IOException { if (lastChars.length() == 1) return findString(lastChars); String[] terminators = new String[lastChars.length()]; for (int i=0; i<terminators.length; i++) { terminators[i] = lastChars.substring(i, i + 1); } return findString(terminators); }
/** * Reads a string ending with one of the characters in the given string. * * @param lastChars string containing possible final characters for the returned string * @return the smallest string that ends in one of the characters in <code>lastChars</code> * @throws IOException If the maximum length (512 MB) is exceeded. * @see #findString(String...) */ public String readString(String lastChars) throws IOException { if (lastChars.length() == 1) return findString(lastChars); String[] terminators = new String[lastChars.length()]; for (int i=0; i<terminators.length; i++) { terminators[i] = lastChars.substring(i, i + 1); } return findString(terminators); }