Skip to content

Commit 99d201a

Browse files
committed
新增:java.io.OutputStream源码
1 parent 1aa891f commit 99d201a

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ Java核心技术学习代码兼测试案例<br>
7070
├── MemoryInputT.java // 内存中输入
7171
├── PipeStreamT.java // 管道输入输出流的的使用
7272
├── RandomAccessFileT.java // RandomAccessFile的使用
73+
├── StoringAndRecoveringData.java // DataOutputStream和DataInputStream的使用案例
7374
├── SystemStreamT.java // System.out, System.err中IO的使用
75+
├── UsingRandomAccessFile.java // RandomAccessFile的使用案例
7476
├── org.javacore.io.byteoper // Java IO 字节操作
7577
├── IntegerConvertT.java // Integer与byte数组转换
7678
├── IntegerOperT.java // Integer类的进制转换
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.javacore.io;
2+
3+
import java.io.Closeable;
4+
import java.io.Flushable;
5+
import java.io.IOException;
6+
7+
/**
8+
* 所有字节输出流实现类的基类
9+
*/
10+
public abstract class SOutputStream implements Closeable, Flushable {
11+
12+
// 将指定的字节写入输出流
13+
public abstract void write(int b) throws IOException;
14+
15+
// 将指定的byte数组的字节全部写入输出流
16+
public void write(byte b[]) throws IOException {
17+
write(b, 0, b.length);
18+
}
19+
20+
// 将指定的byte数组中从偏移量off开始的len个字节写入输出流
21+
public void write(byte b[], int off, int len) throws IOException {
22+
if (b == null) {
23+
throw new NullPointerException();
24+
} else if ((off < 0) || (off > b.length) || (len < 0) ||
25+
((off + len) > b.length) || ((off + len) < 0)) {
26+
throw new IndexOutOfBoundsException();
27+
} else if (len == 0) {
28+
return;
29+
}
30+
for (int i = 0 ; i < len ; i++) {
31+
write(b[off + i]);
32+
}
33+
}
34+
35+
// 刷新输出流,并强制写出所有缓冲的输出字节
36+
public void flush() throws IOException {
37+
}
38+
39+
// 关闭输出流,并释放与该流有关的所有资源
40+
public void close() throws IOException {
41+
}
42+
43+
}

0 commit comments

Comments
 (0)