Java tutorial
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.OutputStream; public class Main { public static final void writeFix(OutputStream out, String s) throws IOException { if (s == null || s.length() == 0) return; byte[] b = s.getBytes(); out.write(b); } public static final void writeFix(OutputStream out, String s, String charsetName) throws IOException { if (s == null || s.length() == 0) return; byte[] b = charsetName != null ? s.getBytes(charsetName) : s.getBytes(); out.write(b); } public static final void writeFix(OutputStream out, String s, int fix) throws IOException { if (fix <= 0) return; byte[] b = s.getBytes(); if (b.length < fix) throw new IOException(); out.write(b, 0, fix); } }