1 package cz.cuni.amis.pogamut.base.communication.connection; 2 3 import java.io.IOException; 4 import java.io.Reader; 5 6 import cz.cuni.amis.pogamut.base.component.bus.exception.ComponentNotRunningException; 7 import cz.cuni.amis.pogamut.base.component.bus.exception.ComponentPausedException; 8 import cz.cuni.amis.utils.exception.PogamutIOException; 9 10 public abstract class WorldReader extends Reader { 11 12 public boolean ready() throws PogamutIOException { 13 try { 14 return super.ready(); 15 } catch (IOException e) { 16 throw new PogamutIOException(e, this); 17 } 18 } 19 20 @Override 21 public abstract void close() throws PogamutIOException; 22 23 @Override 24 public abstract int read(char[] arg0, int arg1, int arg2) throws PogamutIOException, ComponentNotRunningException, ComponentPausedException; 25 26 public static class WorldReaderWrapper extends WorldReader { 27 28 private Reader reader; 29 30 public WorldReaderWrapper(Reader reader) { 31 this.reader = reader; 32 } 33 34 @Override 35 public void close() throws PogamutIOException { 36 try { 37 reader.close(); 38 } catch (IOException e) { 39 throw new PogamutIOException(e, this); 40 } 41 } 42 43 @Override 44 public int read(char[] arg0, int arg1, int arg2) 45 throws PogamutIOException, ComponentNotRunningException { 46 try { 47 return reader.read(arg0, arg1, arg2); 48 } catch (IOException e) { 49 throw new PogamutIOException(e, this); 50 } 51 } 52 53 } 54 55 }