RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.robot.internal.disco.io; 00002 00003 import java.io.BufferedInputStream; 00004 import java.io.EOFException; 00005 import java.io.FileInputStream; 00006 import java.io.IOException; 00007 import java.io.InputStream; 00008 import java.io.ObjectInputStream; 00009 import java.util.Iterator; 00010 import java.util.zip.GZIPInputStream; 00011 00012 00013 public class DiscoLogfile implements Iterator<DiscoPacket> { 00014 private ObjectInputStream objin; 00015 private DiscoPacket nextPacket; 00016 public final String filepath; 00017 00018 public DiscoLogfile(String name) throws IOException { 00019 this.filepath = name; 00020 InputStream input = new FileInputStream(name); 00021 if (name.endsWith(".gz")) 00022 input = new GZIPInputStream(input); 00023 objin = new ObjectInputStream(new BufferedInputStream(input)); 00024 nextPacket = readPacket(); 00025 } 00026 00027 private DiscoPacket readPacket() { 00028 try { 00029 return (DiscoPacket) objin.readObject(); 00030 } catch (EOFException e) { 00031 return null; 00032 } catch (Exception e) { 00033 e.printStackTrace(); 00034 } 00035 return null; 00036 } 00037 00038 @Override 00039 public boolean hasNext() { 00040 return nextPacket != null; 00041 } 00042 00043 public void close() { 00044 try { 00045 objin.close(); 00046 } catch (IOException e) { 00047 e.printStackTrace(); 00048 } 00049 objin = null; 00050 } 00051 00052 @Override 00053 public void remove() { 00054 } 00055 00056 @Override 00057 public DiscoPacket next() { 00058 DiscoPacket result = nextPacket; 00059 nextPacket = readPacket(); 00060 return result; 00061 } 00062 00063 public boolean isClosed() { 00064 return objin == null; 00065 } 00066 }