Example usage for java.io BufferedReader getClass

List of usage examples for java.io BufferedReader getClass

Introduction

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

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:GrowBufferedReader.java

public static void main(String... args) {
    try {//from   ww w .j  a  v a 2 s . c  om
        BufferedReader br = new BufferedReader(car);

        Class<?> c = br.getClass();
        Field f = c.getDeclaredField("cb");

        // cb is a private field
        f.setAccessible(true);
        char[] cbVal = char[].class.cast(f.get(br));

        char[] newVal = Arrays.copyOf(cbVal, cbVal.length * 2);
        if (args.length > 0 && args[0].equals("grow"))
            f.set(br, newVal);

        for (int i = 0; i < srcBufSize; i++)
            br.read();

        // see if the new backing array is being used
        if (newVal[srcBufSize - 1] == src[srcBufSize - 1])
            out.format("Using new backing array, size=%d%n", newVal.length);
        else
            out.format("Using original backing array, size=%d%n", cbVal.length);

        // production code should handle these exceptions more gracefully
    } catch (FileNotFoundException x) {
        x.printStackTrace();
    } catch (NoSuchFieldException x) {
        x.printStackTrace();
    } catch (IllegalAccessException x) {
        x.printStackTrace();
    } catch (IOException x) {
        x.printStackTrace();
    }
}

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

private String readContent(String filename) {
    Reader r = null;/*www .j a  v  a  2  s  .c  o  m*/
    BufferedReader br = null;
    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);
        }
    }
}