Java File Write via ByteBuffer writeStringToSocketChannel(String text, SocketChannel sc)

Here you can find the source of writeStringToSocketChannel(String text, SocketChannel sc)

Description

write String To Socket Channel

License

Apache License

Declaration

public static void writeStringToSocketChannel(String text, SocketChannel sc) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.*;
import java.nio.channels.*;
import java.nio.charset.*;

public class Main {
    private static Charset charset = Charset.forName("ISO-8859-2");

    public static void writeStringToSocketChannel(String text, SocketChannel sc) {
        text += "\n";
        try {//from  w  w  w .j  a va 2s.c  o m
            ByteBuffer buf = charset.encode(text);
            while (buf.hasRemaining()) {
                sc.write(buf);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

Related

  1. writeObject(Serializable serializable)
  2. writeShort(int i, DataOutput out)
  3. writeString(ByteArrayOutputStream bout, String val)
  4. writeStringContents(String contents, WritableByteChannel channel)
  5. writeStringData(DataOutputStream mDataOutputStream, String token)
  6. writeToFile(String path, ByteOrder byteOrder)
  7. writeUtf8(DataOutput out, String string)
  8. writeVector(DataOutputStream output, float[] vector)
  9. writeWaveFile44100_16Bit_Mono(short[] data, File file)