/** * 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. * * @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); }
private String readCString() throws IOException { // long strings are rarely encountered, so using a smaller block size // will be faster than calling in.readCString() return in.findString(true, 64, "\0"); }
private String readCString() throws IOException { // long strings are rarely encountered, so using a smaller block size // will be faster than calling in.readCString() return in.findString(true, 64, "\0"); }
private String readCString() throws IOException { return in.findString(true, 256, "\0"); }
private String readCString() throws IOException { return in.findString(true, 256, "\0"); }
/** * 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); }
/** Read the next line of text from the input stream. */ @Override public String readLine() throws IOException { String line = findString("\n"); return line.length() == 0 ? null : line; }
/** Read the next line of text from the input stream. */ @Override public String readLine() throws IOException { String line = findString("\n"); return line.length() == 0 ? null : line; }
/** Read a string of arbitrary length, terminated by a null char. */ public String readCString() throws IOException { String line = findString("\0"); return line.length() == 0 ? null : line; }
/** * Read a string of arbitrary length, terminated by a null char. * * @return the shortest null-terminated string from the current pointer * @throws IOException if there is an error during reading */ public String readCString() throws IOException { String line = findString("\0"); return line.length() == 0 ? null : line; }
private String readLine() throws IOException { String s = in.findString("\r", "\n"); return s.length() == 0 ? null : s; }
private String readLine() throws IOException { String s = in.findString("\r", "\n"); return s.length() == 0 ? null : s; }
/** * 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 each character is a possible terminator * @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. * @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); }
/** Searches for the divider tag in blocks of the given size. */ public long testBlock(String filename, int blockSize) throws IOException { LOGGER.info("Searching for divider in blocks of {}...", blockSize); long start = System.currentTimeMillis(); RandomAccessInputStream in = new RandomAccessInputStream(filename); long offset = in.findString(blockSize, TAG).length(); in.close(); long end = System.currentTimeMillis(); LOGGER.info("Search result: {} -- in {} ms", offset, end - start); return offset; }
private void parseHeader() throws IOException { String headerData = in.findString("{END}"); dataOffset = in.getFilePointer(); IniParser parser = new IniParser(); ini = parser.parseINI(new BufferedReader(new StringReader(headerData))); }
private void parseHeader() throws IOException { String headerData = in.findString("{END}"); dataOffset = in.getFilePointer(); IniParser parser = new IniParser(); ini = parser.parseINI(new BufferedReader(new StringReader(headerData))); }
private long findPixelsOffset(int fileIndex) throws IOException { String file = files.get(fileIndex); long fp = 0; try (RandomAccessInputStream s = new RandomAccessInputStream(file)) { s.order(isLittleEndian()); s.findString(false, HEADER_MARKER); int plane = FormatTools.getPlaneSize(this); int planeCount = getSizeZ() * getSizeT(); long skip = (s.length() - s.getFilePointer() - (planeCount * plane)) / planeCount; fp = s.getFilePointer() + skip - HEADER_MARKER.length(); s.seek(fp); if (s.readByte() == PIXELS_MARKER[PIXELS_MARKER.length - 1]) { fp++; } } return fp; }