forked from txs72/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixedLengthStringIO.java
More file actions
executable file
·40 lines (38 loc) · 1.19 KB
/
FixedLengthStringIO.java
File metadata and controls
executable file
·40 lines (38 loc) · 1.19 KB
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
35
36
37
38
39
40
/* */ package ch17;
/* */
/* */ import java.io.DataInput;
/* */ import java.io.DataOutput;
/* */ import java.io.IOException;
/* */
/* */ public class FixedLengthStringIO
/* */ {
/* */ public static String readFixedLengthString(int size, DataInput in) throws IOException {
/* 10 */ char[] chars = new char[size];
/* */
/* */
/* 13 */ for (int i = 0; i < size; i++) {
/* 14 */ chars[i] = in.readChar();
/* */ }
/* 16 */ return new String(chars);
/* */ }
/* */
/* */
/* */
/* */ public static void writeFixedLengthString(String s, int size, DataOutput out) throws IOException {
/* 22 */ char[] chars = new char[size];
/* */
/* */
/* 25 */ s.getChars(0, Math.min(s.length(), size), chars, 0);
/* */
/* */
/* 28 */ for (int i = Math.min(s.length(), size); i < chars.length; i++) {
/* 29 */ chars[i] = ' ';
/* */ }
/* */
/* 32 */ out.writeChars(new String(chars));
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch17/FixedLengthStringIO.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/