KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > codec > SeekableOutputStream


1 /*
2
3    Copyright 2001 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.ext.awt.image.codec;
19
20 import java.io.IOException JavaDoc;
21 import java.io.OutputStream JavaDoc;
22 import java.io.RandomAccessFile JavaDoc;
23
24 /**
25  * An <code>OutputStream</code> which can seek to an arbitrary offset.
26  */

27 public class SeekableOutputStream extends OutputStream JavaDoc {
28
29     private RandomAccessFile JavaDoc file;
30
31     /**
32      * Constructs a <code>SeekableOutputStream</code> from a
33      * <code>RandomAccessFile</code>. Unless otherwise indicated,
34      * all method invocations are fowarded to the underlying
35      * <code>RandomAccessFile</code>.
36      *
37      * @param file The <code>RandomAccessFile</code> to which calls
38      * will be forwarded.
39      * @exception IllegalArgumentException if <code>file</code> is
40      * <code>null</code>.
41      */

42     public SeekableOutputStream(RandomAccessFile JavaDoc file) {
43         if(file == null) {
44             throw new IllegalArgumentException JavaDoc("SeekableOutputStream0");
45         }
46         this.file = file;
47     }
48
49     public void write(int b) throws IOException JavaDoc {
50         file.write(b);
51     }
52
53     public void write(byte b[]) throws IOException JavaDoc {
54         file.write(b);
55     }
56
57     public void write(byte b[], int off, int len) throws IOException JavaDoc {
58         file.write(b, off, len);
59     }
60
61     /**
62      * Invokes <code>getFD().sync()</code> on the underlying
63      * <code>RandomAccessFile</code>.
64      */

65     public void flush() throws IOException JavaDoc {
66         file.getFD().sync();
67     }
68
69     public void close() throws IOException JavaDoc {
70         file.close();
71     }
72
73     public long getFilePointer() throws IOException JavaDoc {
74         return file.getFilePointer();
75     }
76
77     public void seek(long pos) throws IOException JavaDoc {
78         file.seek(pos);
79     }
80 }
81
Popular Tags