|
1 | 1 | /* |
2 | | - * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
20 | 20 | * or visit www.oracle.com if you need additional information or have any |
21 | 21 | * questions. |
22 | 22 | */ |
| 23 | + |
23 | 24 | package nsk.share; |
24 | 25 |
|
25 | | -import java.io.*; |
| 26 | +import jdk.test.lib.Utils; |
| 27 | + |
| 28 | +import java.io.IOException; |
| 29 | +import java.nio.charset.StandardCharsets; |
| 30 | +import java.nio.file.Files; |
| 31 | +import java.nio.file.Path; |
26 | 32 |
|
27 | | -public class GoldChecker extends AbstractGoldChecker |
28 | | -{ |
| 33 | +public class GoldChecker extends AbstractGoldChecker { |
29 | 34 | private final String goldOutput; |
30 | 35 |
|
31 | | - public GoldChecker(String main_class_name) { |
32 | | - goldOutput = readGoldStr(main_class_name + ".gold"); |
| 36 | + public GoldChecker(String mainClassName) { |
| 37 | + goldOutput = readGoldStr(Path.of(Utils.TEST_SRC, mainClassName + ".gold")); |
33 | 38 | } |
34 | 39 |
|
35 | 40 | @Override |
36 | 41 | protected String getGoldenString() { |
37 | 42 | return goldOutput; |
38 | 43 | } |
39 | 44 |
|
40 | | - private String readGoldStr(String gold_file_name) { |
41 | | - RandomAccessFile f; |
42 | | - |
43 | | - try { |
44 | | - f = new RandomAccessFile(gold_file_name, "r"); |
45 | | - } catch (FileNotFoundException e) { |
46 | | - throw new TestBug("Unable to open golden file '" + gold_file_name + "' for reading"); |
| 45 | + private String readGoldStr(Path goldenFile) { |
| 46 | + if (Files.notExists(goldenFile)) { |
| 47 | + throw new TestBug("Unable to open golden file '" + goldenFile + "' for reading"); |
47 | 48 | } |
48 | | - |
49 | 49 | byte[] data; |
50 | | - |
51 | 50 | try { |
52 | | - int len = (int)f.length(); |
53 | | - data = new byte[len]; |
54 | | - f.read(data); |
| 51 | + data = Files.readAllBytes(goldenFile); |
55 | 52 | } catch (IOException e) { |
56 | | - throw new TestBug("Error reading from golden file'" + gold_file_name + "'"); |
57 | | - } |
58 | | - |
59 | | - try { |
60 | | - f.close(); |
61 | | - } catch (IOException e) { |
62 | | - } |
63 | | - |
64 | | - try { |
65 | | - return new String(data, "US-ASCII"); |
66 | | - } catch (UnsupportedEncodingException e) { |
67 | | - throw new TestFailure( e ); |
| 53 | + throw new TestBug("Error reading from golden file '" + goldenFile + "'", e); |
68 | 54 | } |
| 55 | + return new String(data, StandardCharsets.US_ASCII); |
69 | 56 | } |
70 | 57 |
|
71 | 58 | } |
0 commit comments