import java.io.*;
// Utility class for reading/writing Strings of fixed length padded with zeroes
public class IOStringUtils
{
// out parameter is a RandomAccessFile object
// length is the size of the fixed length string to be written
public static void writeFixedString(
DataOutput out, int length, String s)
throws IOException
{
for (int i = 0; i < length; i++)
{
if (i < s.length())
out.writeChar(s.charAt(i)); // write char
else
out.writeChar(0); // write Unicode zero
}
}
// in parameter is a RandomAccessFile object
public static String readFixedString(
DataInput in, int length) throws IOException
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++)
{
char c = in.readChar();
// if char is not Unicode zero add to string
if (c != 0)
sb.append(c);
}
return sb.toString();
}
}//class IOStringUtils