Java Code Examples for java.io.BufferedReader.markSupported()

The following are Jave code examples for showing how to use markSupported() of the java.io.BufferedReader class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: jaer   File: AEFileInputStream.java   Source Code and License Vote up 5 votes
/**
 * reads the header comment lines. Must have eventSize and chunkSizeBytes
 * set for backwards compatiblity for files without headers to short address
 * sizes.
 */
protected void readHeader(FileInputStream fileInputStream) throws IOException {

    if (fileInputStream == null) {
        throw new IOException("null fileInputStream");
    }
    if (fileInputStream.available() == 0) {
        throw new IOException("empty file (0 bytes available)");
    }

    BufferedReader bufferedHeaderReader = new BufferedReader(new InputStreamReader(fileInputStream));
    headerOffset = 0; // start from 0
    if (!bufferedHeaderReader.markSupported()) {
        throw new IOException("no mark supported while reading file header, is this a normal file?");
    }
    String s;
    // System.out.println("File header:");
    while ((s = readHeaderLine(bufferedHeaderReader)) != null) {
        header.add(s);
        parseFileFormatVersion(s);
    }
    // we don't map yet until we know eventSize
    StringBuilder sb = new StringBuilder();
    sb.append("File header (clipped to " + NUM_HEADER_LINES_TO_PRINT + " lines: \n");
    int nLines = 0;
    for (String str : header) {
        sb.append(str);
        sb.append(lineSeparator); // "\n");
        if (nLines++ > NUM_HEADER_LINES_TO_PRINT) {
            break;
        }
    }
    log.info(sb.toString());
    bufferedHeaderReader = null; // mark for GC, but don't close or underlying channel breaks!
}
 
Example 2
Project: spring-rest-basis   File: LoggingRequestInterceptor.java   Source Code and License Vote up 5 votes
private void logResponse(ClientHttpResponse response,
        final BufferedReader bufferedReader) throws IOException {
    log("============================response begin==========================================");
    log("status code: {}", response.getStatusCode());
    log("status text: {}", response.getStatusText());
    if (bufferedReader.markSupported()) {
        writeBody(bufferedReader);
    }
    bufferedReader.close();
    log("=======================response end=================================================");
}