public <R> Observable<R> observable( Func1<? super T, ? extends Observable<? extends R>> observableFactory) { return Observable.using(resourceFactory, observableFactory, disposeAction, disposeEagerly); }
public static Observable<String> from(final Func0<Reader> readerFactory) { Func1<Reader, Observable<String>> observableFactory = new Func1<Reader, Observable<String>>() { @Override public Observable<String> call(Reader reader) { return from(reader); } }; return Observable.using(readerFactory, observableFactory, DisposeActionHolder.INSTANCE, true); }
public static Observable<String> from(final Func0<Reader> readerFactory) { Func1<Reader, Observable<String>> observableFactory = new Func1<Reader, Observable<String>>() { @Override public Observable<String> call(Reader reader) { return from(reader); } }; return Observable.using(readerFactory, observableFactory, DisposeActionHolder.INSTANCE, true); }
public <R> Observable<R> observable( Func1<? super T, ? extends Observable<? extends R>> observableFactory) { return Observable.using(resourceFactory, observableFactory, disposeAction, disposeEagerly); }
public static Observable<byte[]> from(final File file, final int size) { Func0<InputStream> resourceFactory = new Func0<InputStream>() { @Override public InputStream call() { try { return new BufferedInputStream(new FileInputStream(file), size); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } }; Func1<InputStream, Observable<byte[]>> observableFactory = new Func1<InputStream, Observable<byte[]>>() { @Override public Observable<byte[]> call(InputStream is) { return from(is, size); } }; return Observable.using(resourceFactory, observableFactory, InputStreamCloseHolder.INSTANCE, true); }
public <T> Observable<T> read(final Class<T> cls, final File file, final int bufferSize) { Func0<Input> resourceFactory = new Func0<Input>() { @Override public Input call() { try { return new Input(new FileInputStream(file), bufferSize); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } }; Func1<Input, Observable<? extends T>> observableFactory = new Func1<Input, Observable<? extends T>>() { @Override public Observable<? extends T> call(final Input input) { return read(cls, input, bufferSize); } }; Action1<Input> disposeAction = new Action1<Input>() { @Override public void call(Input input) { input.close(); } }; return Observable.using(resourceFactory, observableFactory, disposeAction, true); }
public static Observable<byte[]> from(final File file, final int size) { Func0<InputStream> resourceFactory = new Func0<InputStream>() { @Override public InputStream call() { try { return new BufferedInputStream(new FileInputStream(file), size); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } }; Func1<InputStream, Observable<byte[]>> observableFactory = new Func1<InputStream, Observable<byte[]>>() { @Override public Observable<byte[]> call(InputStream is) { return from(is, size); } }; return Observable.using(resourceFactory, observableFactory, InputStreamCloseHolder.INSTANCE, true); }
return Observable.using(resourceFactory, observableFactory, disposeAction, true);
public static Observable<ZippedEntry> unzip(final File file) { Func0<ZipInputStream> resourceFactory = new Func0<ZipInputStream>() { @Override public ZipInputStream call() { try { return new ZipInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } }; Func1<ZipInputStream, Observable<ZippedEntry>> observableFactory = ZipHolder.OBSERVABLE_FACTORY; Action1<ZipInputStream> disposeAction = ZipHolder.DISPOSER; return Observable.using(resourceFactory, observableFactory, disposeAction); }
public <T> Observable<T> read(final Class<T> cls, final File file, final int bufferSize) { Func0<Input> resourceFactory = new Func0<Input>() { @Override public Input call() { try { return new Input(new FileInputStream(file), bufferSize); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } }; Func1<Input, Observable<? extends T>> observableFactory = new Func1<Input, Observable<? extends T>>() { @Override public Observable<? extends T> call(final Input input) { return read(cls, input, bufferSize); } }; Action1<Input> disposeAction = new Action1<Input>() { @Override public void call(Input input) { input.close(); } }; return Observable.using(resourceFactory, observableFactory, disposeAction, true); }
return Observable.using(resourceFactory, observableFactory, disposeAction, true);
public static Observable<ZippedEntry> unzip(final File file) { Func0<ZipInputStream> resourceFactory = new Func0<ZipInputStream>() { @Override public ZipInputStream call() { try { return new ZipInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } }; Func1<ZipInputStream, Observable<ZippedEntry>> observableFactory = ZipHolder.OBSERVABLE_FACTORY; Action1<ZipInputStream> disposeAction = ZipHolder.DISPOSER; return Observable.using(resourceFactory, observableFactory, disposeAction); }
public static Observable<String> nmeaFrom(final File file) { return Observable.using( // Checked.f0(() -> new FileInputStream(file)), is -> nmeaFrom(is), // is -> { try { is.close(); } catch (IOException e) { // don't care } } , true); }
public static Observable<String> nmeaFromGzip(final File file) { Func0<Reader> resourceFactory = () -> { try { return new InputStreamReader(new GZIPInputStream(new FileInputStream(file)), UTF8); } catch (IOException e) { throw new RuntimeException(e); } }; Func1<Reader, Observable<String>> observableFactory = reader -> Strings .split(Strings.from(reader), "\n"); Action1<Reader> disposeAction = reader -> { try { reader.close(); } catch (IOException e) { // ignore } }; return Observable.using(resourceFactory, observableFactory, disposeAction, true); }
public static Observable<Map<String, String>> extractMaps(File file, String parentElementName) { Func0<InputStream> resourceFactory = Checked.f0(() -> new FileInputStream(file)); Func1<InputStream, Observable<Map<String, String>>> observableFactory = is -> Observable .just(is).lift(new OperatorIhsReader(parentElementName)); Action1<InputStream> disposeAction = Checked.a1(is -> is.close()); return Observable.using(resourceFactory, observableFactory, disposeAction); }
public static Observable<Observable<byte[]>> create( final Func0<? extends ServerSocket> serverSocketFactory, final int timeoutMs, final int bufferSize, Action0 preAcceptAction, int acceptTimeoutMs, Func1<? super Socket, Boolean> acceptSocket) { Func1<ServerSocket, Observable<Observable<byte[]>>> observableFactory = createObservableFactory( timeoutMs, bufferSize, preAcceptAction, acceptSocket); return Observable.<Observable<byte[]>, ServerSocket> using( // createServerSocketFactory(serverSocketFactory, acceptTimeoutMs), // observableFactory, // new Action1<ServerSocket>() { @Override public void call(ServerSocket ss) { try { ss.close(); } catch (IOException e) { throw new RuntimeException(e); } } }, true); }
public static Observable<Observable<byte[]>> create( final Func0<? extends ServerSocket> serverSocketFactory, final int timeoutMs, final int bufferSize, Action0 preAcceptAction, int acceptTimeoutMs, Func1<? super Socket, Boolean> acceptSocket) { Func1<ServerSocket, Observable<Observable<byte[]>>> observableFactory = createObservableFactory( timeoutMs, bufferSize, preAcceptAction, acceptSocket); return Observable.<Observable<byte[]>, ServerSocket> using( // createServerSocketFactory(serverSocketFactory, acceptTimeoutMs), // observableFactory, // new Action1<ServerSocket>() { @Override public void call(ServerSocket ss) { try { ss.close(); } catch (IOException e) { throw new RuntimeException(e); } } }, true); }
private static Observable<byte[]> createSocketObservable(final Socket socket, long timeoutMs, final int bufferSize) { setTimeout(socket, timeoutMs); return Observable.using( // Checked.f0(new F0<InputStream>() { @Override public InputStream call() throws Exception { return socket.getInputStream(); } }), // new Func1<InputStream, Observable<byte[]>>() { @Override public Observable<byte[]> call(InputStream is) { return Bytes.from(is, bufferSize); } }, // Actions.close(), // true); }
private static Observable<byte[]> createSocketObservable(final Socket socket, long timeoutMs, final int bufferSize) { setTimeout(socket, timeoutMs); return Observable.using( // Checked.f0(new F0<InputStream>() { @Override public InputStream call() throws Exception { return socket.getInputStream(); } }), // new Func1<InputStream, Observable<byte[]>>() { @Override public Observable<byte[]> call(InputStream is) { return Bytes.from(is, bufferSize); } }, // Actions.close(), // true); }
public static Observable<String> strings(Func0<Socket> socketCreator, final Charset charset) { Preconditions.checkNotNull(socketCreator); Preconditions.checkNotNull(charset); return Observable // create a stream from a socket and dispose of socket // appropriately .using(socketCreator, socketObservableFactory(charset), socketDisposer(), true); }