01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.store.fs;
07:
08: /**
09: * Allows to write to a file object like an output stream.
10: */
11: import java.io.IOException;
12: import java.io.OutputStream;
13:
14: public class FileObjectOutputStream extends OutputStream {
15:
16: private FileObject file;
17: private byte[] buffer = new byte[1];
18:
19: FileObjectOutputStream(FileObject file, boolean append)
20: throws IOException {
21: this .file = file;
22: if (append) {
23: file.seek(file.length());
24: } else {
25: file.seek(0);
26: file.setFileLength(0);
27: }
28: }
29:
30: public void write(int b) throws IOException {
31: buffer[0] = (byte) b;
32: file.write(buffer, 0, 1);
33: }
34:
35: public void write(byte[] b) throws IOException {
36: file.write(b, 0, b.length);
37: }
38:
39: public void write(byte[] b, int off, int len) throws IOException {
40: file.write(b, off, len);
41: }
42:
43: public void close() throws IOException {
44: file.close();
45: }
46:
47: }
|