1 package au.gov.amsa.ais; 2 3 import java.io.InputStream; 4 import java.io.InputStreamReader; 5 import java.nio.charset.Charset; 6 7 import rx.functions.Func1; 8 import au.gov.amsa.streams.Strings; 9 import au.gov.amsa.util.nmea.NmeaReader; 10 11 public class NmeaReaderFromInputStream implements NmeaReader { 12 13 private static final Func1<String, Boolean> NON_EMPTY = new Func1<String, Boolean>() { 14 @Override 15 public Boolean call(String s) { 16 return s.trim().length() > 0; 17 } 18 }; 19 20 private final InputStream is; 21 22 public NmeaReaderFromInputStream(InputStream is) { 23 this.is = is; 24 } 25 26 @Override 27 public Iterable<String> read() { 28 return Strings 29 .split(Strings.from(new InputStreamReader(is, Charset 30 .forName("UTF-8"))), "\n").filter(NON_EMPTY) 31 .toBlocking().toIterable(); 32 } 33 }