1 6 21 22 package de.schlichtherle.io.util; 23 24 import java.io.*; 25 26 34 public class SynchronizedInputStream extends InputStream { 35 38 protected final Object lock; 39 40 43 protected InputStream in; 44 45 51 public SynchronizedInputStream(final InputStream in) { 52 this(in, null); 53 } 54 55 62 public SynchronizedInputStream(final InputStream in, final Object lock) { 63 this.in = in; 64 this.lock = lock != null ? lock : this; 65 } 66 67 public int read() throws IOException { 68 synchronized (lock) { 69 return in.read(); 70 } 71 } 72 73 public int read(byte[] b) throws IOException { 74 synchronized (lock) { 75 return read(b, 0, b.length); 76 } 77 } 78 79 public int read(byte[] b, int off, int len) throws IOException { 80 synchronized (lock) { 81 return in.read(b, off, len); 82 } 83 } 84 85 public long skip(long n) throws IOException { 86 synchronized (lock) { 87 return in.skip(n); 88 } 89 } 90 91 public int available() throws IOException { 92 synchronized (lock) { 93 return in.available(); 94 } 95 } 96 97 public void close() throws IOException { 98 synchronized (lock) { 99 in.close(); 100 } 101 } 102 103 public void mark(int readlimit) { 104 synchronized (lock) { 105 in.mark(readlimit); 106 } 107 } 108 109 public void reset() throws IOException { 110 synchronized (lock) { 111 in.reset(); 112 } 113 } 114 115 public boolean markSupported() { 116 synchronized (lock) { 117 return in.markSupported(); 118 } 119 } 120 } 121 | Popular Tags |