Add basic support for Java 7 NIO file systems (#20293)

This commit is contained in:
Michał Kiędyś 2016-04-25 19:25:26 +10:00 committed by Konrad Malawski
parent 6d399a308e
commit b983f19c1f
23 changed files with 286 additions and 124 deletions

View file

@ -3,7 +3,7 @@
*/
package docs.stream;
import java.io.File;
import java.nio.file.Paths;
import java.math.BigInteger;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
@ -56,7 +56,7 @@ public class QuickStartDocTest {
final CompletionStage<IOResult> result =
factorials
.map(num -> ByteString.fromString(num.toString() + "\n"))
.runWith(FileIO.toFile(new File("factorials.txt")), materializer);
.runWith(FileIO.toPath(Paths.get("factorials.txt")), materializer);
//#transform-source
//#use-transformed-sink
@ -81,7 +81,7 @@ public class QuickStartDocTest {
public Sink<String, CompletionStage<IOResult>> lineSink(String filename) {
return Flow.of(String.class)
.map(s -> ByteString.fromString(s.toString() + "\n"))
.toMat(FileIO.toFile(new File(filename)), Keep.right());
.toMat(FileIO.toPath(Paths.get(filename)), Keep.right());
}
//#transform-sink

View file

@ -3,7 +3,9 @@
*/
package docs.stream.io;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.IOException;
import java.util.concurrent.CompletionStage;
@ -47,13 +49,13 @@ public class StreamFileDocTest extends AbstractJavaTest {
{
//#file-source
final File file = new File("example.csv");
final Path file = Paths.get("example.csv");
//#file-source
}
@Test
public void demonstrateMaterializingBytesWritten() throws IOException {
final File file = File.createTempFile(getClass().getName(), ".tmp");
final Path file = Files.createTempFile(getClass().getName(), ".tmp");
try {
//#file-source
@ -61,27 +63,27 @@ public class StreamFileDocTest extends AbstractJavaTest {
Sink.<ByteString> foreach(chunk -> System.out.println(chunk.utf8String()));
CompletionStage<IOResult> ioResult =
FileIO.fromFile(file)
FileIO.fromPath(file)
.to(printlnSink)
.run(mat);
//#file-source
} finally {
file.delete();
Files.delete(file);
}
}
@Test
public void demonstrateSettingDispatchersInCode() throws IOException {
final File file = File.createTempFile(getClass().getName(), ".tmp");
final Path file = Files.createTempFile(getClass().getName(), ".tmp");
try {
Sink<ByteString, CompletionStage<IOResult>> fileSink =
//#custom-dispatcher-code
FileIO.toFile(file)
FileIO.toPath(file)
.withAttributes(ActorAttributes.dispatcher("custom-blocking-io-dispatcher"));
//#custom-dispatcher-code
} finally {
file.delete();
Files.delete(file);
}
}