1 /* language convertion www.dsource.org/project/tioport */ 2 module java.io.ByteArrayInputStream; 3 4 import java.io.InputStream; 5 6 public class ByteArrayInputStream : java.io.InputStream.InputStream { 7 8 alias java.io.InputStream.InputStream.read read; 9 alias java.io.InputStream.InputStream.skip skip; 10 alias java.io.InputStream.InputStream.available available; 11 alias java.io.InputStream.InputStream.close close; 12 alias java.io.InputStream.InputStream.mark mark; 13 alias java.io.InputStream.InputStream.reset reset; 14 alias java.io.InputStream.InputStream.markSupported markSupported; 15 16 protected byte[] buf; 17 protected int pos; 18 protected int fld_mark = 0; 19 //protected int count; 20 public this ( byte[] aBuf ){ 21 this.buf = aBuf; 22 } 23 24 public this ( byte[] aBuf, int offset, int length_ESCAPE ){ 25 this.buf = aBuf[ offset .. offset+length_ESCAPE ]; 26 } 27 28 override 29 public int read(){ 30 synchronized { 31 if( pos >= this.buf.length ){ 32 return -1; 33 } 34 int result = this.buf[pos]; 35 pos++; 36 return result & 0xFF; 37 } 38 } 39 40 override 41 public ptrdiff_t read( byte[] b, ptrdiff_t off, ptrdiff_t len ){ 42 synchronized return super.read( b, off, len ); 43 } 44 45 override 46 public long skip( long n ){ 47 synchronized { 48 pos += n; 49 return 0L; 50 } 51 } 52 53 override 54 public ptrdiff_t available(){ 55 synchronized { 56 if( pos >= this.buf.length ){ 57 return 0; 58 } 59 return cast(int)(this.buf.length - pos); 60 } 61 } 62 63 override 64 public bool markSupported(){ 65 return false; 66 } 67 68 override 69 public synchronized void mark( int readAheadLimit ){ 70 } 71 72 override 73 public synchronized void reset(){ 74 pos = 0; 75 } 76 77 override 78 public void close(){ 79 } 80 81 82 } 83 84