1 32 33 package com.hp.hpl.jena.shared.wg; 34 35 36 import java.io.*; 37 38 44 abstract class LazyInputStream extends InputStream { 45 46 private InputStream underlying; 47 abstract InputStream open() throws IOException; 48 49 boolean connect() throws IOException { 50 if ( underlying != null ) 51 return true; 52 else { 53 underlying = open(); 54 } 55 return underlying != null; 56 57 } 58 59 60 public int read() throws IOException { 61 if (underlying == null) 62 underlying = open(); 63 return underlying.read(); 64 } 65 66 public void close() throws IOException { 67 if (underlying != null) { 68 underlying.close(); 69 underlying = null; 70 } 71 } 72 73 74 75 } 76 | Popular Tags |