< prev index next >
1 /*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package java.net.http;
25
26 import java.io.*;
27 import java.net.*;
28 import java.nio.file.*;
29 import java.util.concurrent.*;
30
31 public class TestUtil {
32
33 final static String fileContent = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // repeated
34
35 public static Path getAFile(int size) throws IOException {
36 Path p = tempFile();
37 BufferedWriter writer = Files.newBufferedWriter(p);
38 int len = fileContent.length();
39 int iterations = size / len;
40 int remainder = size - (iterations * len);
41 for (int i=0; i<iterations; i++)
42 writer.write(fileContent, 0, len);
43 writer.write(fileContent, 0, remainder);
44 writer.close();
45 return p;
46 }
47
48 public static Path tempFile() {
49 try {
50 Path p = Files.createTempFile("foo", "test");
51 p.toFile().deleteOnExit();
52 return p;
53 } catch (IOException e) {
54 throw new UncheckedIOException(e);
55 }
56 }
57
58 public static Void compareFiles(Path path1, Path path2) {
59 try {
60 if (Files.size(path1) != Files.size(path2))
61 throw new RuntimeException("File sizes do not match");
62 else
63 return null;
64 } catch (IOException e) {
65 throw new UncheckedIOException(e);
66 }
67 }
68
69 }
< prev index next >