changeset 60457:363929dc4fcf

8251126: nsk.share.GoldChecker should read golden file from ${test.src} Reviewed-by: dholmes
author iignatyev
date Wed, 05 Aug 2020 16:39:38 -0700
parents 5db028403de8
children d3b0c0747b42
files test/hotspot/jtreg/vmTestbase/nsk/share/GoldChecker.java
diffstat 1 files changed, 20 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/GoldChecker.java	Wed Aug 05 16:39:08 2020 -0700
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/GoldChecker.java	Wed Aug 05 16:39:38 2020 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -20,16 +20,21 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
 package nsk.share;
 
-import java.io.*;
+import jdk.test.lib.Utils;
 
-public class GoldChecker extends AbstractGoldChecker
-{
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+public class GoldChecker extends AbstractGoldChecker {
     private final String goldOutput;
 
-    public GoldChecker(String main_class_name) {
-        goldOutput = readGoldStr(main_class_name + ".gold");
+    public GoldChecker(String mainClassName) {
+        goldOutput = readGoldStr(Path.of(Utils.TEST_SRC, mainClassName + ".gold"));
     }
 
     @Override
@@ -37,35 +42,17 @@
         return goldOutput;
     }
 
-    private String readGoldStr(String gold_file_name) {
-        RandomAccessFile f;
-
+    private String readGoldStr(Path goldenFile) {
+        if (Files.notExists(goldenFile)) {
+            throw new TestBug("Unable to open golden file '" + goldenFile + "' for reading");
+        }
+        byte[] data;
         try {
-            f = new RandomAccessFile(gold_file_name, "r");
-        } catch (FileNotFoundException e) {
-            throw new TestBug("Unable to open golden file '" + gold_file_name + "' for reading");
+            data = Files.readAllBytes(goldenFile);
+        } catch (IOException e) {
+            throw new TestBug("Error reading from golden file '" + goldenFile + "'", e);
         }
-
-        byte[] data;
-
-        try {
-            int len = (int)f.length();
-            data = new byte[len];
-            f.read(data);
-        } catch (IOException e) {
-            throw new TestBug("Error reading from golden file'" + gold_file_name + "'");
-        }
-
-        try {
-            f.close();
-        } catch (IOException e) {
-        }
-
-        try {
-            return new String(data, "US-ASCII");
-        } catch (UnsupportedEncodingException e) {
-            throw new TestFailure( e );
-        }
+        return new String(data, StandardCharsets.US_ASCII);
     }
 
 }