Example usage for io.netty.buffer ByteBuf asReadOnly

List of usage examples for io.netty.buffer ByteBuf asReadOnly

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf asReadOnly.

Prototype

public abstract ByteBuf asReadOnly();

Source Link

Document

Returns a read-only version of this buffer.

Usage

From source file:com.heliosapm.streams.collector.groovy.ByteBufReaderSource.java

License:Apache License

/**
 * Loads the source file into a ByteBuf and returns it as a read only buffer
 * @return the loaded ByteBuf/*from   www.j  ava  2 s. com*/
 */
protected ByteBuf loadSourceFile() {
    ByteBuf buf = BufferManager.getInstance().directBuffer((int) this.sourceFile.length());
    FileReader fr = null;
    BufferedReader br = null;
    String line = null;
    try {
        fr = new FileReader(sourceFile);
        br = new BufferedReader(fr);
        while ((line = br.readLine()) != null) {
            final String enrichedLine = StringHelper.resolveTokens(line, scriptProperties);
            buf.writeCharSequence(enrichedLine + EOL, UTF8);
        }
        return buf.asReadOnly();
    } catch (Exception ex) {
        throw new RuntimeException("Failed to read source from source file [" + sourceFile + "]", ex);
    } finally {
        if (br != null)
            try {
                br.close();
            } catch (Exception x) {
                /* No Op */}
        if (fr != null)
            try {
                fr.close();
            } catch (Exception x) {
                /* No Op */}
    }
}