-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.java
More file actions
57 lines (48 loc) · 1.32 KB
/
benchmark.java
File metadata and controls
57 lines (48 loc) · 1.32 KB
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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Scanner;
import org.junit.Before;
import org.junit.Test;
public class io {
private StringBuilder sb;
private static final String FILEPATH = "/home/jigar/Desktop/ML/dataset.txt";
@Before
public void setup() {
sb = new StringBuilder();
}
@Test
public void testNio() throws Exception {
Path resource = Paths.get(FILEPATH);
FileChannel input = FileChannel.open(resource, StandardOpenOption.READ);
ByteBuffer buffer = ByteBuffer.allocate(1024);
while (input.read(buffer) > -1) {
buffer.flip();
while (buffer.remaining() > 0)
sb.append((char) buffer.get());
buffer.flip();
}
input.close();
}
@Test
public void testScanner() throws Exception {
Scanner sc = new Scanner(new File(FILEPATH));
while (sc.hasNext())
sb.append(sc.nextLine());
sc.close();
}
@Test
public void testBufferedReader() throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(FILEPATH)));
String temp;
while ((temp = br.readLine()) != null)
sb.append(temp);
br.close();
}
}