/** * Returns a reader that decodes bytes from a channel. This method creates a * reader with a buffer of default size. * * @param channel * the Channel to be read. * @param charsetName * the name of the charset. * @return the reader. * @throws java.nio.charset.UnsupportedCharsetException * if the given charset name is not supported. */ public static Reader newReader(ReadableByteChannel channel, String charsetName) { if (charsetName == null) { throw new NullPointerException("charsetName == null"); } return newReader(channel, Charset.forName(charsetName).newDecoder(), -1); }
/** * Creates a {@code Scanner} with the specified {@code ReadableByteChannel} as * input. The specified charset is applied when decoding the input. * * @param src * the {@code ReadableByteChannel} to be scanned. * @param charsetName * the encoding type of the content. * @throws IllegalArgumentException * if the specified character set is not found. */ public Scanner(ReadableByteChannel src, String charsetName) { if (src == null) { throw new NullPointerException("src == null"); } if (charsetName == null) { throw new IllegalArgumentException("charsetName == null"); } setInput(Channels.newReader(src, charsetName)); }
Reader reader = Channels.newReader(socketChannel, sourceEncoding); Writer writer = Channels.newWriter(socketChannel, sourceEncoding); CharBuffer buffer = CharBuffer.allocate(maxLineLength);
private static Readable makeReadable(ReadableByteChannel source, CharsetDecoder dec) { return Channels.newReader(source, dec, -1); }
// Later, read from the file using the file API lock = false; // Let other people read at the same time FileReadChannel readChannel = fileService.openReadChannel(file, false); // Again, different standard Java ways of reading from the channel. BufferedReader reader = new BufferedReader(Channels.newReader(readChannel, "UTF8")); String line = reader.readLine(); // line = "The woods are lovely dark and deep."
public RgxReader(String fileName, Charset charset, int _limit) throws FileNotFoundException { this(CharBuffer.allocate(1024)); fs = new FileInputStream(fileName); ReadableByteChannel channel = fs.getChannel(); CharsetDecoder decoder = charset.newDecoder(); reader = Channels.newReader(channel, decoder, -1); buf.limit(0); limit = _limit; }
CharsetDecoder dec=StandardCharsets.UTF_8.newDecoder() .onMalformedInput(CodingErrorAction.IGNORE); Path path=Paths.get(getClass().getClassLoader().getResource("bigtest.txt").toURI()); List<String> lines; try(Reader r=Channels.newReader(FileChannel.open(path), dec, -1); BufferedReader br=new BufferedReader(r)) { lines=br.lines() .filter(s -> s.regionMatches(true, 0, "aa", 0, 2)) .collect(Collectors.toList()); }
CharsetDecoder dec=StandardCharsets.UTF_8.newDecoder() .onMalformedInput(CodingErrorAction.REPLACE); Path path=Paths.get(getClass().getClassLoader().getResource("bigtest.txt").toURI()); List<String> lines; try(Reader r=Channels.newReader(FileChannel.open(path), dec, -1); BufferedReader br=new BufferedReader(r)) { lines=br.lines() .filter(s->!s.contains(dec.replacement())) .filter(s -> s.regionMatches(true, 0, "aa", 0, 2)) .collect(Collectors.toList()); }
/** * returns this {@link ReadableByteChannel} as {@link Reader} * @return the input stream */ public Reader toReader() { return Channels.newReader(this, getEncoding()); }
private void stop() { try ( SocketChannel socket = SocketChannel.open(); PrintWriter writer = new PrintWriter(Channels.newWriter(socket, StandardCharsets.UTF_8.name()), true); BufferedReader reader = new BufferedReader(Channels.newReader(socket, StandardCharsets.UTF_8.name()))) { socket.connect(new InetSocketAddress("localhost", controlPort)); } catch (IOException e) { // bury } }
private void stop() { try ( SocketChannel socket = SocketChannel.open(); PrintWriter writer = new PrintWriter(Channels.newWriter(socket, StandardCharsets.UTF_8.name()), true); BufferedReader reader = new BufferedReader(Channels.newReader(socket, StandardCharsets.UTF_8.name()))) { socket.connect(new InetSocketAddress("localhost", controlPort)); } catch (IOException e) { // bury } }
private void stop() { try ( SocketChannel socket = SocketChannel.open(); PrintWriter writer = new PrintWriter(Channels.newWriter(socket, StandardCharsets.UTF_8.name()), true); BufferedReader reader = new BufferedReader(Channels.newReader(socket, StandardCharsets.UTF_8.name()))) { socket.connect(new InetSocketAddress("localhost", controlPort)); } catch (IOException e) { // bury } }
int readCount = 0; int BUFFER_SIZE = 256; StringBuilder sb = new StringBuilder(); CharBuffer cBuffer= CharBuffer.allocate(BUFFER_SIZE); ReadableByteChannel readableByteChannel = Channels.newChannel(is); Reader reader=Channels.newReader(readableByteChannel, "UTF-8"); while(reader.read(cBuffer) > 0 && readCount < 68) { cBuffer.flip(); sb.append(cBuffer); cBuffer.clear(); readCount++; }
FormatterOptions read() throws IOException { if (channel == null) { init(); } channel.position(0); Reader reader = Channels.newReader(channel, StandardCharsets.UTF_8.name()); Properties properties = new Properties(); properties.load(reader); return FormatterOptions.create( properties.getProperty("toolVersion"), parseOptions(properties.getProperty("options"))); }
// Get a file service FileService fileService = FileServiceFactory.getFileService(); // Get a file backed by blob AppEngineFile file = fileService.getBlobFile(blobKey) // get a read channel FileReadChannel readChannel = fileService.openReadChannel(file, false); // Since you store a String, I guess you want to read it a such BufferedReader reader = new BufferedReader(Channels.newReader(readChannel, "UTF8")); // Do this in loop unitil all data is read String line = reader.readLine();
public <T extends Element> Document<T> parse(ReadableByteChannel buf, String base, ParserOptions options) throws ParseException { String charset = options.getCharset(); return parse(Channels.newReader(buf, charset != null ? charset : "utf-8"), base, options); }
@Override public HashMap<String, JsonElement> getAttributes(final String pathName) throws IOException { final Path path = Paths.get(basePath, getAttributesPath(pathName).toString()); if (exists(pathName) && !Files.exists(path)) return new HashMap<>(); try (final LockedFileChannel lockedFileChannel = LockedFileChannel.openForReading(path)) { return GsonAttributesParser.readAttributes(Channels.newReader(lockedFileChannel.getFileChannel(), StandardCharsets.UTF_8.name()), getGson()); } }
/** * Get a reader that can reader from this pipe. The pipe must be readable */ public Reader getReader(String charset) { checkNotFlipped(); return new PipeChannelReader(this, Channels.newReader(pipe.source(), charset)); }
/** * Get a reader that can reader from this pipe. The pipe must be readable */ public Reader getReader() { checkNotFlipped(); return new PipeChannelReader(this, Channels.newReader(pipe.source(), charset)); }
/** * Open test output for reading for single file test results. */ public BufferedReader openOutput(String outputPath) throws IOException { return new BufferedReader(Channels.newReader(gcsUtil.open(GcsPath.fromUri(outputPath)), "UTF-8")); }