-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSFileOutputStream.java
More file actions
206 lines (206 loc) · 6.59 KB
/
SFileOutputStream.java
File metadata and controls
206 lines (206 loc) · 6.59 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//package org.javacore.io;
//
//import java.io.File;
//import java.io.FileDescriptor;
//import java.io.FileNotFoundException;
//import java.io.IOException;
//import java.io.OutputStream;
//import java.nio.channels.FileChannel;
//
//import sun.misc.IoTrace;
//import sun.nio.ch.FileChannelImpl;
//
///**
// * 文件输入流是用于将数据写入文件或者文件描述符类
// * 比如写入图片等的原始字节流。如果写入字符流,考虑使用 FiLeWriter。
// */
//public class SFileOutputStream extends OutputStream
//{
// /* 文件描述符类---此处用于打开文件的句柄 */
// private final FileDescriptor fd;
//
// /* 引用文件的路径 */
// private final String path;
//
// /* 如果为 true,则将字节写入文件末尾处,而不是写入文件开始处 */
// private final boolean append;
//
// /* 关联的FileChannel类,懒加载 */
// private FileChannel channel;
//
// private final Object closeLock = new Object();
// private volatile boolean closed = false;
// private static final ThreadLocal<Boolean> runningFinalize =
// new ThreadLocal<>();
//
// private static boolean isRunningFinalize() {
// Boolean val;
// if ((val = runningFinalize.get()) != null)
// return val.booleanValue();
// return false;
// }
//
// /* 通过文件名创建文件输入流 */
// public FileOutputStream(String name) throws FileNotFoundException {
// this(name != null ? new File(name) : null, false);
// }
//
// /* 通过文件名创建文件输入流,并确定文件写入起始处模式 */
// public FileOutputStream(String name, boolean append)
// throws FileNotFoundException
// {
// this(name != null ? new File(name) : null, append);
// }
//
// /* 通过文件创建文件输入流,默认写入文件的开始处 */
// public FileOutputStream(File file) throws FileNotFoundException {
// this(file, false);
// }
//
// /* 通过文件创建文件输入流,并确定文件写入起始处 */
// public FileOutputStream(File file, boolean append)
// throws FileNotFoundException
// {
// String name = (file != null ? file.getPath() : null);
// SecurityManager security = System.getSecurityManager();
// if (security != null) {
// security.checkWrite(name);
// }
// if (name == null) {
// throw new NullPointerException();
// }
// if (file.isInvalid()) {
// throw new FileNotFoundException("Invalid file path");
// }
// this.fd = new FileDescriptor();
// this.append = append;
// this.path = name;
// fd.incrementAndGetUseCount();
// open(name, append);
// }
//
// /* 通过文件描述符类创建文件输入流 */
// public FileOutputStream(FileDescriptor fdObj) {
// SecurityManager security = System.getSecurityManager();
// if (fdObj == null) {
// throw new NullPointerException();
// }
// if (security != null) {
// security.checkWrite(fdObj);
// }
// this.fd = fdObj;
// this.path = null;
// this.append = false;
//
// fd.incrementAndGetUseCount();
// }
//
// /* 打开文件,并确定文件写入起始处模式 */
// private native void open(String name, boolean append)
// throws FileNotFoundException;
//
// /* 将指定的字节b写入到该文件输入流,并指定文件写入起始处模式 */
// private native void write(int b, boolean append) throws IOException;
//
// /* 将指定的字节b写入到该文件输入流 */
// public void write(int b) throws IOException {
// Object traceContext = IoTrace.fileWriteBegin(path);
// int bytesWritten = 0;
// try {
// write(b, append);
// bytesWritten = 1;
// } finally {
// IoTrace.fileWriteEnd(traceContext, bytesWritten);
// }
// }
//
// /* 将指定的字节数组写入该文件输入流,并指定文件写入起始处模式 */
// private native void writeBytes(byte b[], int off, int len, boolean append)
// throws IOException;
//
// /* 将指定的字节数组b写入该文件输入流 */
// public void write(byte b[]) throws IOException {
// Object traceContext = IoTrace.fileWriteBegin(path);
// int bytesWritten = 0;
// try {
// writeBytes(b, 0, b.length, append);
// bytesWritten = b.length;
// } finally {
// IoTrace.fileWriteEnd(traceContext, bytesWritten);
// }
// }
//
// /* 将指定len长度的字节数组b写入该文件输入流 */
// public void write(byte b[], int off, int len) throws IOException {
// Object traceContext = IoTrace.fileWriteBegin(path);
// int bytesWritten = 0;
// try {
// writeBytes(b, off, len, append);
// bytesWritten = len;
// } finally {
// IoTrace.fileWriteEnd(traceContext, bytesWritten);
// }
// }
//
// /* 关闭此文件输出流并释放与此流有关的所有系统资源 */
// public void close() throws IOException {
// synchronized (closeLock) {
// if (closed) {
// return;
// }
// closed = true;
// }
//
// if (channel != null) {
// fd.decrementAndGetUseCount();
// channel.close();
// }
//
// int useCount = fd.decrementAndGetUseCount();
//
// if ((useCount <= 0) || !isRunningFinalize()) {
// close0();
// }
// }
//
// public final FileDescriptor getFD() throws IOException {
// if (fd != null) return fd;
// throw new IOException();
// }
//
// public FileChannel getChannel() {
// synchronized (this) {
// if (channel == null) {
// channel = FileChannelImpl.open(fd, path, false, true, append, this);
//
// fd.incrementAndGetUseCount();
// }
// return channel;
// }
// }
//
// protected void finalize() throws IOException {
// if (fd != null) {
// if (fd == FileDescriptor.out || fd == FileDescriptor.err) {
// flush();
// } else {
//
// runningFinalize.set(Boolean.TRUE);
// try {
// close();
// } finally {
// runningFinalize.set(Boolean.FALSE);
// }
// }
// }
// }
//
// private native void close0() throws IOException;
//
// private static native void initIDs();
//
// static {
// initIDs();
// }
//
//}