本文整理了Java中java.nio.channels.Channels.newReader()
方法的一些代码示例,展示了Channels.newReader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Channels.newReader()
方法的具体详情如下:
包路径:java.nio.channels.Channels
类名称:Channels
方法名:newReader
[英]Returns a reader that decodes bytes from a channel. This method creates a reader with a buffer of default size.
[中]
代码示例来源:origin: robovm/robovm
/**
* 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);
}
代码示例来源:origin: robovm/robovm
/**
* 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));
}
代码示例来源:origin: apache/flume
Reader reader = Channels.newReader(socketChannel, sourceEncoding);
Writer writer = Channels.newWriter(socketChannel, sourceEncoding);
CharBuffer buffer = CharBuffer.allocate(maxLineLength);
代码示例来源:origin: stackoverflow.com
private static Readable makeReadable(ReadableByteChannel source, CharsetDecoder dec) {
return Channels.newReader(source, dec, -1);
}
代码示例来源:origin: stackoverflow.com
// 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."
代码示例来源:origin: ripreal/V8LogScanner
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;
}
代码示例来源:origin: stackoverflow.com
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());
}
代码示例来源:origin: stackoverflow.com
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());
}
代码示例来源:origin: org.xlightweb/xlightweb
/**
* returns this {@link ReadableByteChannel} as {@link Reader}
* @return the input stream
*/
public Reader toReader() {
return Channels.newReader(this, getEncoding());
}
代码示例来源:origin: io.github.gradle-clojure/gradle-clojure-plugin
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
}
}
代码示例来源:origin: gradle.plugin.com.github.anolivetree/gradle-clojure-plugin
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
}
}
代码示例来源:origin: gradle-clojure/gradle-clojure
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
}
}
代码示例来源:origin: stackoverflow.com
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++;
}
代码示例来源:origin: gradle.plugin.com.github.sherter.google-java-format/google-java-format-gradle-plugin
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")));
}
代码示例来源:origin: stackoverflow.com
// 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();
代码示例来源:origin: org.apache.abdera/abdera-core
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);
}
代码示例来源:origin: saalfeldlab/n5
@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());
}
}
代码示例来源:origin: org.apache.abdera/abdera-i18n
/**
* 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));
}
代码示例来源:origin: org.apache.abdera/abdera-i18n
/**
* 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));
}
代码示例来源:origin: googlegenomics/dataflow-java
/**
* 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"));
}
内容来源于网络,如有侵权,请联系作者删除!