1 18 19 package com.martiansoftware.nailgun; 20 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 24 35 class ThreadLocalInputStream extends InputStream { 36 37 40 private InheritableThreadLocal streams = null; 41 42 private InputStream defaultInputStream = null; 43 44 48 ThreadLocalInputStream(InputStream defaultInputStream) { 49 super(); 50 streams = new InheritableThreadLocal (); 51 this.defaultInputStream = defaultInputStream; 52 init(null); 53 } 54 55 59 void init(InputStream streamForCurrentThread) { 60 streams.set(streamForCurrentThread); 61 } 62 63 67 InputStream getInputStream() { 68 InputStream result = (InputStream ) streams.get(); 69 return ((result == null) ? defaultInputStream : result); 70 } 71 72 74 77 public int available() throws IOException { 78 return (getInputStream().available()); 79 } 80 81 84 public void close() throws IOException { 85 getInputStream().close(); 86 } 87 88 91 public void mark(int readlimit) { 92 getInputStream().mark(readlimit); 93 } 94 95 98 public boolean markSupported() { 99 return (getInputStream().markSupported()); 100 } 101 102 105 public int read() throws IOException { 106 return (getInputStream().read()); 107 } 108 109 112 public int read(byte[] b) throws IOException { 113 return (getInputStream().read(b)); 114 } 115 116 119 public int read(byte[] b, int off, int len) throws IOException { 120 return (getInputStream().read(b, off, len)); 121 } 122 123 126 public void reset() throws IOException { 127 getInputStream().reset(); 128 } 129 130 133 public long skip(long n) throws IOException { 134 return (getInputStream().skip(n)); 135 } 136 137 139 } 145 | Popular Tags |