-
Notifications
You must be signed in to change notification settings - Fork 580
/
Readers.java
94 lines (79 loc) · 2.49 KB
/
Readers.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* Copyright 2015 Twitter, Inc. */
package com.twitter.io;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;
import java.util.stream.Stream;
import com.twitter.concurrent.AsyncStream;
import com.twitter.util.Future;
import scala.collection.JavaConverters;
import scala.runtime.BoxedUnit;
/**
* Better Java APIs of Reader for Scala 2.11.
* This will be removed when drop Scala 2.11 support.
*
* @see com.twitter.io.Reader
*/
public final class Readers {
private Readers() { throw new IllegalStateException(); }
public static <A> Reader<A> newEmptyReader() {
return Reader$.MODULE$.<A>empty();
}
/**
* See {@code com.twitter.io.Reader.fromBuf}.
*/
public static Reader<Buf> newBufReader(Buf buf, int chunkSize) {
return Reader$.MODULE$.fromBuf(buf, chunkSize);
}
/**
* See {@code com.twitter.io.Reader.concat}.
*/
public static Reader<Buf> concat(AsyncStream<Reader<Buf>> readers) {
return Reader$.MODULE$.concat(readers);
}
/**
* See {@code com.twitter.io.Reader.copy}.
*/
public static Future<BoxedUnit> copy(Reader<Buf> r, Writer<Buf> w) {
return Reader$.MODULE$.copy(r, w);
}
/**
* See {@code com.twitter.io.Reader.copyMany}.
*/
public static Future<BoxedUnit> copyMany(AsyncStream<Reader<Buf>> readers, Writer<Buf> w) {
return Reader$.MODULE$.copyMany(readers, w);
}
/**
* See {@code com.twitter.io.Reader.fromFile()}.
*/
public static Reader<Buf> newFileReader(File f, int chunkSize) throws FileNotFoundException {
return Reader$.MODULE$.fromFile(f, chunkSize);
}
/**
* See {@code com.twitter.io.Reader.fromStream()}.
*/
public static Reader<Buf> newInputStreamReader(InputStream in, int chunkSize) {
return Reader$.MODULE$.fromStream(in, chunkSize);
}
/**
* See [[com.twitter.io.Reader$#fromSeq(scala.collection.Seq)]]
*/
public static <A> Reader<A> fromSeq(List<A> list) {
return Reader$.MODULE$.fromSeq(JavaConverters.asScalaIteratorConverter(list.iterator())
.asScala().toSeq());
}
/**
* See [[com.twitter.io.Reader$#fromSeq(scala.collection.Seq)]]
*/
public static <A> Reader<A> fromSeq(Stream<A> stream) {
return Reader$.MODULE$.fromSeq(JavaConverters.asScalaIteratorConverter(stream.iterator())
.asScala().toSeq());
}
/**
* See [[com.twitter.io.Reader#toAsyncStream]]
*/
public static <A> AsyncStream<A> toAsyncStream(Reader<A> reader) {
return Reader$.MODULE$.toAsyncStream(reader);
}
}