List of usage examples for io.netty.buffer ByteBuf asReadOnly
public abstract ByteBuf asReadOnly();
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 */} } }