Java DataOutputStream Write String writeString(String s, DataOutputStream writer)

Here you can find the source of writeString(String s, DataOutputStream writer)

Description

write String

License

Open Source License

Declaration

public static void writeString(String s, DataOutputStream writer) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;

import java.io.DataOutputStream;

public class Main {
    public static void writeString(String s, DataOutputStream writer) throws Exception {
        if (s != null) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);
            byte[] data = s.getBytes("UTF-8");
            dos.writeInt(data.length);/*  www  .  jav  a  2 s.  c  om*/
            dos.write(data);
            dos.flush();
            byte[] bs = bos.toByteArray();
            writer.write(bs);
            writer.flush();
        }
    }
}

Related

  1. writeString(final DataOutputStream out, final String str)
  2. writeString(final DataOutputStream out, final String value)
  3. writeString(String arg, DataOutputStream data)
  4. writeString(String s, DataOutputStream out)
  5. writeString(String s, DataOutputStream out)
  6. writeString(String str, DataOutputStream dos)
  7. writeString(String str, DataOutputStream os)
  8. writeString(String stringToWrite, DataOutputStream data)
  9. writeStringAsBytes(DataOutputStream out, byte[] byteArray)