1 // Handler.java - URLStreamHandler for core protocol.
3 /* Copyright (C) 2001 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 package gnu
.java
.net
.protocol
.core
;
14 import gnu
.gcj
.RawData
;
15 import java
.io
.InputStream
;
16 import java
.io
.IOException
;
18 public class CoreInputStream
extends InputStream
20 /* A pointer to the object in memory. */
21 protected RawData ptr
;
23 /* Position of the next byte in core to be read. */
26 /* The currently marked position in the stream. */
29 /* The index in core one greater than the last valid character. */
32 private native int unsafeGetByte (long offset
);
33 private native int copyIntoByteArray (byte[] dest
, int offset
, int numBytes
);
35 public CoreInputStream (Core core
)
41 public synchronized int available()
46 public synchronized void mark(int readAheadLimit
)
48 // readAheadLimit is ignored per Java Class Lib. book, p.220.
52 public boolean markSupported()
57 public synchronized int read()
60 return ((int) unsafeGetByte(pos
++)) & 0xFF;
64 public synchronized int read(byte[] b
, int off
, int len
)
69 int numBytes
= Math
.min(count
- pos
, len
);
70 copyIntoByteArray (b
, off
, numBytes
);
75 public synchronized void reset()
80 public synchronized long skip(long n
)
82 // Even though the var numBytes is a long, in reality it can never
83 // be larger than an int since the result of subtracting 2 positive
84 // ints will always fit in an int. Since we have to return a long
85 // anyway, numBytes might as well just be a long.
86 long numBytes
= Math
.min ((long) (count
- pos
), n
< 0 ?
0L : n
);