Here you can find the source of writeString(OutputStream out, String str)
Parameter | Description |
---|---|
out | The OutputStream to write the string to |
str | The string to write |
Parameter | Description |
---|---|
IOException | an exception |
public static void writeString(OutputStream out, String str) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.OutputStream; import java.util.Arrays; public class Main { private static final byte[] buffer = new byte[1024]; /**/*w ww . ja v a 2 s. c om*/ * Write a string (not null-terminated). * * @param out The OutputStream to write the string to * @param str The string to write * @throws IOException */ public static void writeString(OutputStream out, String str) throws IOException { out.write(str.getBytes()); } /** * Write a number of bytes * * @param out The OutputStream to write to * @param data The bytes to write * @throws IOException */ public static void write(OutputStream out, byte[] data) throws IOException { out.write(data); } /** * Write a repeated byte value. * * @param out The OutputStream to write to * @param value The value to write * @param count Number of times to write the value */ public static void write(final OutputStream out, final int value, final int count) throws IOException { if (count > buffer.length) { // Fallback for (int i = 0; i < count; i++) { writeByte(out, value); } } else { Arrays.fill(buffer, (byte) value); out.write(buffer, 0, count); } } /** * Write a byte. * * @param out The OutputStream to write the byte to * @param value The byte to write * @throws IOException */ public static void writeByte(OutputStream out, int value) throws IOException { out.write(value); } }