forked from mthli/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataIO.java
More file actions
34 lines (31 loc) · 749 Bytes
/
DataIO.java
File metadata and controls
34 lines (31 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package randomAccess;
import java.io.*;
public class DataIO
{
public static String readFixedString(int size, DataInput in)
throws IOException
{
StringBuilder b = new StringBuilder(size);
int i = 0;
boolean more = true;
while (more && i < size)
{
char ch = in.readChar();
i++;
if (ch == 0) more = false;
else b.append(ch);
}
in.skipBytes(2 * (size - i));
return b.toString();
}
public static void writeFixedString(String s, int size, DataOutput out)
throws IOException
{
for (int i = 0; i < size; i++)
{
char ch = 0;
if (i < s.length()) ch = s.charAt(i);
out.writeChar(ch);
}
}
}