!str - Moving the InputStream and OutputStream utilities into Source and Sink
This commit is contained in:
parent
cb8d3c4609
commit
8780ba28a4
25 changed files with 432 additions and 310 deletions
|
|
@ -2,6 +2,7 @@ package docs;
|
|||
|
||||
import akka.actor.Cancellable;
|
||||
import akka.http.javadsl.model.Uri;
|
||||
import akka.japi.function.Creator;
|
||||
import akka.japi.Pair;
|
||||
import akka.japi.function.Function;
|
||||
import akka.stream.*;
|
||||
|
|
@ -14,6 +15,9 @@ import scala.concurrent.Promise;
|
|||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
|
|
@ -22,6 +26,15 @@ public class MigrationsJava {
|
|||
// This is compile-only code, no need for actually running anything.
|
||||
public static ActorMaterializer mat = null;
|
||||
|
||||
public static class SomeInputStream extends InputStream {
|
||||
public SomeInputStream() {}
|
||||
@Override public int read() throws IOException { return 0; }
|
||||
}
|
||||
|
||||
public static class SomeOutputStream extends OutputStream {
|
||||
@Override public void write(int b) throws IOException { return; }
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Outlet<Integer> outlet = null;
|
||||
|
|
@ -160,6 +173,47 @@ public class MigrationsJava {
|
|||
final Sink<ByteString, Future<Long>> fileSink =
|
||||
Sink.file(new File("."));
|
||||
//#file-source-sink
|
||||
|
||||
//#input-output-stream-source-sink
|
||||
final Source<ByteString, Future<java.lang.Long>> inputStreamSrc =
|
||||
Source.inputStream(new Creator<InputStream>(){
|
||||
public InputStream create() {
|
||||
return new SomeInputStream();
|
||||
}
|
||||
});
|
||||
|
||||
final Source<ByteString, Future<java.lang.Long>> otherInputStreamSrc =
|
||||
Source.inputStream(new Creator<InputStream>(){
|
||||
public InputStream create() {
|
||||
return new SomeInputStream();
|
||||
}
|
||||
}, 1024);
|
||||
|
||||
final Sink<ByteString, Future<java.lang.Long>> outputStreamSink =
|
||||
Sink.outputStream(new Creator<OutputStream>(){
|
||||
public OutputStream create() {
|
||||
return new SomeOutputStream();
|
||||
}
|
||||
});
|
||||
//#input-output-stream-source-sink
|
||||
|
||||
|
||||
//#output-input-stream-source-sink
|
||||
final FiniteDuration timeout = FiniteDuration.Zero();
|
||||
|
||||
final Source<ByteString, OutputStream> outputStreamSrc =
|
||||
Source.outputStream();
|
||||
|
||||
final Source<ByteString, OutputStream> otherOutputStreamSrc =
|
||||
Source.outputStream(timeout);
|
||||
|
||||
final Sink<ByteString, InputStream> someInputStreamSink =
|
||||
Sink.inputStream();
|
||||
|
||||
final Sink<ByteString, InputStream> someOtherInputStreamSink =
|
||||
Sink.inputStream(timeout);
|
||||
//#output-input-stream-source-sink
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -424,17 +424,17 @@ should be replaced by:
|
|||
SynchronousFileSource and SynchronousFileSink
|
||||
============================================
|
||||
|
||||
Both have been replaced by `Source.file(…)` and `Sink.file(…)` due to discoverability issues
|
||||
Both have been replaced by ``Source.file(…)`` and ``Sink.file(…)`` due to discoverability issues
|
||||
paired with names which leaked internal implementation details.
|
||||
|
||||
Update procedure
|
||||
----------------
|
||||
|
||||
Replace `SynchronousFileSource.create(` with `Source.file(`
|
||||
Replace ``SynchronousFileSource.create(`` with ``Source.file(``
|
||||
|
||||
Replace `SynchronousFileSink.create(` with `Sink.file(`
|
||||
Replace ``SynchronousFileSink.create(`` with ``Sink.file(``
|
||||
|
||||
Replace `SynchronousFileSink.appendTo(f)` with `Sink.file(f, true)`
|
||||
Replace ``SynchronousFileSink.appendTo(f)`` with ``Sink.file(f, true)``
|
||||
|
||||
Example
|
||||
^^^^^^^
|
||||
|
|
@ -455,4 +455,87 @@ Example
|
|||
|
||||
should be replaced by
|
||||
|
||||
.. includecode:: code/docs/MigrationsJava.java#file-source-sink
|
||||
.. includecode:: code/docs/MigrationsJava.java#file-source-sink
|
||||
|
||||
InputStreamSource and OutputStreamSink
|
||||
======================================
|
||||
|
||||
Both have been replaced by ``Source.inputStream(…)`` and ``Sink.outputStream(…)`` due to discoverability issues.
|
||||
|
||||
Update procedure
|
||||
----------------
|
||||
|
||||
Replace ``InputStreamSource.create(`` with ``Source.inputStream(``
|
||||
|
||||
Replace ``OutputStreamSink.create(`` with ``Sink.outputStream(``
|
||||
|
||||
Example
|
||||
^^^^^^^
|
||||
|
||||
::
|
||||
|
||||
// This no longer works!
|
||||
final Source<ByteString, Future<java.lang.Long>> inputStreamSrc =
|
||||
InputStreamSource.create(new Creator<InputStream>(){
|
||||
public InputStream create() {
|
||||
return new SomeInputStream();
|
||||
}
|
||||
});
|
||||
|
||||
// This no longer works!
|
||||
final Source<ByteString, Future<java.lang.Long>> otherInputStreamSrc =
|
||||
InputStreamSource.create(new Creator<InputStream>(){
|
||||
public InputStream create() {
|
||||
return new SomeInputStream();
|
||||
}
|
||||
}, 1024);
|
||||
|
||||
// This no longer works!
|
||||
final Sink<ByteString, Future<java.lang.Long>> outputStreamSink =
|
||||
OutputStreamSink.create(new Creator<OutputStream>(){
|
||||
public OutputStream create() {
|
||||
return new SomeOutputStream();
|
||||
}
|
||||
})
|
||||
|
||||
should be replaced by
|
||||
|
||||
.. includecode:: code/docs/MigrationsJava.java#input-output-stream-source-sink
|
||||
|
||||
|
||||
OutputStreamSource and InputStreamSink
|
||||
======================================
|
||||
|
||||
Both have been replaced by ``Source.outputStream(…)`` and ``Sink.inputStream(…)`` due to discoverability issues.
|
||||
|
||||
Update procedure
|
||||
----------------
|
||||
|
||||
Replace ``OutputStreamSource.create(`` with ``Source.outputStream(``
|
||||
|
||||
Replace ``InputStreamSink.create(`` with ``Sink.inputStream(``
|
||||
|
||||
Example
|
||||
^^^^^^^
|
||||
|
||||
::
|
||||
|
||||
// This no longer works!
|
||||
final Source<ByteString, OutputStream> outputStreamSrc =
|
||||
OutputStreamSource.create();
|
||||
|
||||
// This no longer works!
|
||||
final Source<ByteString, OutputStream> otherOutputStreamSrc =
|
||||
OutputStreamSource.create(timeout);
|
||||
|
||||
// This no longer works!
|
||||
final Sink<ByteString, InputStream> someInputStreamSink =
|
||||
InputStreamSink.create();
|
||||
|
||||
// This no longer works!
|
||||
final Sink<ByteString, InputStream> someOtherInputStreamSink =
|
||||
InputStreamSink.create(timeout);
|
||||
|
||||
should be replaced by
|
||||
|
||||
.. includecode:: code/docs/MigrationsJava.java#output-input-stream-source-sink
|
||||
Loading…
Add table
Add a link
Reference in a new issue