本文整理了Java中java.nio.channels.Channels.newWriter()
方法的一些代码示例,展示了Channels.newWriter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Channels.newWriter()
方法的具体详情如下:
包路径:java.nio.channels.Channels
类名称:Channels
方法名:newWriter
[英]Returns a writer that encodes characters with the specified encoder and sends the bytes to the specified channel. This method creates a writer with a buffer of default size.
[中]返回使用指定编码器编码字符并将字节发送到指定通道的写入程序。此方法使用默认大小的缓冲区创建写入程序。
代码示例来源:origin: robovm/robovm
/**
* Returns a writer that encodes characters with the specified
* {@code encoder} and sends the bytes to the specified channel. This method
* creates a writer with a buffer of default size.
*
* @param channel
* the Channel to be written to.
* @param charsetName
* the name of the charset.
* @return the writer.
* @throws java.nio.charset.UnsupportedCharsetException
* if the given charset name is not supported.
*/
public static Writer newWriter(WritableByteChannel channel,
String charsetName) {
if (charsetName == null) {
throw new NullPointerException("charsetName == null");
}
return newWriter(channel, Charset.forName(charsetName).newEncoder(), -1);
}
代码示例来源:origin: thymeleaf/thymeleaf
this.writer = Channels.newWriter(channel, charsetEncoder, channelBufferSize);
代码示例来源:origin: apache/flume
Writer writer = Channels.newWriter(socketChannel, sourceEncoding);
CharBuffer buffer = CharBuffer.allocate(maxLineLength);
代码示例来源:origin: igniterealtime/Openfire
/**
* Create a new session using the supplied socket.
*
* @param backupDeliverer the packet deliverer this connection will use when socket is closed.
* @param socket the socket to represent.
* @param isSecure true if this is a secure connection.
* @throws java.io.IOException if there was a socket error while sending the packet.
*/
public SocketConnection(PacketDeliverer backupDeliverer, Socket socket, boolean isSecure)
throws IOException {
if (socket == null) {
throw new NullPointerException("Socket channel must be non-null");
}
this.secure = isSecure;
this.socket = socket;
// DANIELE: Modify socket to use channel
if (socket.getChannel() != null) {
writer = Channels.newWriter(
ServerTrafficCounter.wrapWritableChannel(socket.getChannel()), StandardCharsets.UTF_8.newEncoder(), -1);
}
else {
writer = new BufferedWriter(new OutputStreamWriter(
ServerTrafficCounter.wrapOutputStream(socket.getOutputStream()), StandardCharsets.UTF_8));
}
this.backupDeliverer = backupDeliverer;
xmlSerializer = new XMLSocketWriter(writer, this);
instances.put(this, "");
// Default this sensibly.
this.tlsPolicy = this.getConfiguration().getTlsPolicy();
}
代码示例来源:origin: stackoverflow.com
String charSetName = ...
CharsetEncoder encoder = Charset.forName(charSetName).newEncoder();
OutputStream out = ...
int bufferSize = ...
WritableByteChannel channel = Channels.newChannel(out);
Writer writer = Channels.newWriter(channel, encoder, bufferSize);
代码示例来源:origin: stackoverflow.com
private static void write0a(StringBuilder sb, Boolean append) throws Exception {
File file = File.createTempFile("foo", ".txt");
try(Writer writer = Channels.newWriter(new FileOutputStream(
file.getAbsoluteFile(), append).getChannel(), "UTF-8")) {
writer.append(sb);
}
}
代码示例来源:origin: org.apache.aries.spifly/org.apache.aries.spifly.dynamic.bundle
public static void store(Object o, Path path, Charset encoding) throws IOException {
try (FileChannel ch = writeChannel(path)) {
if (o != null) {
try (Writer w = Channels.newWriter(ch, encoding.newEncoder(), -1)) {
w.write(o.toString());
}
}
}
}
代码示例来源:origin: org.osgi/osgi.enroute.configurer.simple.provider
public static void store(Object o, Path path, Charset encoding) throws IOException {
try (FileChannel ch = writeChannel(path)) {
if (o != null) {
try (Writer w = Channels.newWriter(ch, encoding.newEncoder(), -1)) {
w.write(o.toString());
}
}
}
}
代码示例来源:origin: biz.aQute.bnd/biz.aQute.bndlib
public static void store(Object o, Path path, Charset encoding) throws IOException {
try (FileChannel ch = writeChannel(path)) {
if (o != null) {
try (Writer w = Channels.newWriter(ch, encoding.newEncoder(), -1)) {
w.write(o.toString());
}
}
}
}
代码示例来源:origin: biz.aQute.bnd/biz.aQute.repository
public static void store(Object o, Path path, Charset encoding) throws IOException {
try (FileChannel ch = writeChannel(path)) {
if (o != null) {
try (Writer w = Channels.newWriter(ch, encoding.newEncoder(), -1)) {
w.write(o.toString());
}
}
}
}
代码示例来源:origin: biz.aQute.bnd/biz.aQute.bnd
public static void store(Object o, Path path, Charset encoding) throws IOException {
try (FileChannel ch = writeChannel(path)) {
if (o != null) {
try (Writer w = Channels.newWriter(ch, encoding.newEncoder(), -1)) {
w.write(o.toString());
}
}
}
}
代码示例来源:origin: biz.aQute.bnd/biz.aQute.resolve
public static void store(Object o, Path path, Charset encoding) throws IOException {
try (FileChannel ch = writeChannel(path)) {
if (o != null) {
try (Writer w = Channels.newWriter(ch, encoding.newEncoder(), -1)) {
w.write(o.toString());
}
}
}
}
代码示例来源: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.plugin.com.github.sherter.google-java-format/google-java-format-gradle-plugin
void write(FormatterOptions options) throws IOException {
if (channel == null) {
init();
}
channel.truncate(0);
Writer writer = Channels.newWriter(channel, StandardCharsets.UTF_8.name());
Properties properties = new Properties();
properties.setProperty("toolVersion", options.version());
properties.setProperty("options", serialize(options.options()));
properties.store(writer, "Generated; DO NOT CHANGE!!!");
}
代码示例来源:origin: org.apache.abdera/abdera-i18n
/**
* Get a writer that can write to this pipe. The pipe must be writable
*/
public Writer getWriter() {
checkFlipped();
return new PipeChannelWriter(this, Channels.newWriter(pipe.sink(), charset));
}
代码示例来源:origin: org.alfresco/alfresco-repository
@Override
protected Writer createUnderlyingLogWriter(String transferId)
{
NodeRef node = new NodeRef(transferId);
ContentWriter contentWriter = contentService.getWriter(node, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML);
contentWriter.setEncoding("UTF-8");
return Channels.newWriter(contentWriter.getWritableChannel(), "UTF-8");
}
}
代码示例来源:origin: org.alfresco/alfresco-repository
protected Writer createUnderlyingLogWriter(String transferId)
{
if (reportFile == null)
{
reportFile = createTransferRecord(transferId);
}
ContentWriter contentWriter = contentService.getWriter(reportFile, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML);
contentWriter.setEncoding("UTF-8");
return Channels.newWriter(contentWriter.getWritableChannel(), "UTF-8");
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
private void createFileWithContent(Path path, String content) throws Exception {
try (Writer writer =
Channels.newWriter(
localFileSystem.create(
LocalResourceId.fromPath(path, false /* isDirectory */),
StandardCreateOptions.builder().setMimeType(MimeTypes.TEXT).build()),
StandardCharsets.UTF_8.name())) {
writer.write(content);
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
private void createFileWithContent(Path path, String content) throws Exception {
try (Writer writer =
Channels.newWriter(
localFileSystem.create(
LocalResourceId.fromPath(path, false /* isDirectory */),
CreateOptions.StandardCreateOptions.builder().setMimeType(MimeTypes.TEXT).build()),
StandardCharsets.UTF_8.name())) {
writer.write(content);
}
}
内容来源于网络,如有侵权,请联系作者删除!