Example usage for java.io Reader getClass

List of usage examples for java.io Reader getClass

Introduction

In this page you can find the example usage for java.io Reader getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.norconex.commons.lang.io.IOUtil.java

/**
 * Wraps the reader in a {@link BufferedReader} if not a subclass already.
 * @param reader the reader to wrap if needed
 * @return buffered reader/*from  w w  w . j av  a  2  s .com*/
 * @since 1.6.0
 */
public static BufferedReader toBufferedReader(Reader reader) {
    if (reader == null) {
        throw new IllegalArgumentException("Reader cannot be null");
    }
    if (BufferedReader.class.isAssignableFrom(reader.getClass())) {
        return (BufferedReader) reader;
    }
    return new BufferedReader(reader);
}

From source file:com.bt.aloha.testing.JdbcHelper.java

private String readContent(String filename) {
    Reader r = null;
    BufferedReader br = null;/*from w  w  w. ja  v a  2 s.c  o m*/
    InputStream is = null;
    try {
        is = JdbcHelper.class.getClassLoader().getResourceAsStream(filename);
        r = new InputStreamReader(is);
        br = new BufferedReader(r);
        StringBuffer sb = new StringBuffer();
        String line = "";
        while ((line = br.readLine()) != null) {
            if (line.indexOf(SERIAL) != -1)
                sb.append(line.replaceAll(SERIAL, INT_IDENTITY));
            else
                sb.append(line);
        }
        String content = sb.toString();
        return content;
    } catch (Throwable e) {
        throw new IllegalArgumentException(String.format("Couldn't read content of create script %s", filename),
                e);
    } finally {
        try {
            if (br != null)
                br.close();
        } catch (IOException e) {
            log.error(String.format(ERROR_CLOSING_S, br.getClass().getSimpleName()), e);
        }
        try {
            if (r != null)
                r.close();
        } catch (IOException e) {
            log.error(String.format(ERROR_CLOSING_S, r.getClass().getSimpleName()), e);
        }
        try {
            if (is != null)
                is.close();
        } catch (IOException e) {
            log.error(String.format(ERROR_CLOSING_S, is.getClass().getSimpleName()), e);
        }
    }
}