test/testlibrary/com/oracle/java/testlibrary/Utils.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8038953 Sdiff test/testlibrary/com/oracle/java/testlibrary

test/testlibrary/com/oracle/java/testlibrary/Utils.java

Print this page
rev 6205 : imported patch 8038953


 277 
 278     /**
 279      * Returns file content as a list of strings
 280      *
 281      * @param file File to operate on
 282      * @return List of strings
 283      * @throws IOException
 284      */
 285     public static List<String> fileAsList(File file) throws IOException {
 286         assertTrue(file.exists() && file.isFile(),
 287                 file.getAbsolutePath() + " does not exist or not a file");
 288         List<String> output = new ArrayList<>();
 289         try (BufferedReader reader = new BufferedReader(new FileReader(file.getAbsolutePath()))) {
 290             while (reader.ready()) {
 291                 output.add(reader.readLine().replace(NEW_LINE, ""));
 292             }
 293         }
 294         return output;
 295     }
 296 



















 297 }


 277 
 278     /**
 279      * Returns file content as a list of strings
 280      *
 281      * @param file File to operate on
 282      * @return List of strings
 283      * @throws IOException
 284      */
 285     public static List<String> fileAsList(File file) throws IOException {
 286         assertTrue(file.exists() && file.isFile(),
 287                 file.getAbsolutePath() + " does not exist or not a file");
 288         List<String> output = new ArrayList<>();
 289         try (BufferedReader reader = new BufferedReader(new FileReader(file.getAbsolutePath()))) {
 290             while (reader.ready()) {
 291                 output.add(reader.readLine().replace(NEW_LINE, ""));
 292             }
 293         }
 294         return output;
 295     }
 296 
 297     private static final char[] hexArray = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
 298 
 299     /**
 300      * Returns hex view of byte array
 301      *
 302      * @param bytes byte array to process
 303      * @return Space separated hexadecimal string representation of bytes
 304      */
 305 
 306     public static String toHexString(byte[] bytes) {
 307         char[] hexView = new char[bytes.length * 3];
 308         int i = 0;
 309         for (byte b : bytes) {
 310             hexView[i++] = hexArray[(b >> 4) & 0x0F];
 311             hexView[i++] = hexArray[b & 0x0F];
 312             hexView[i++] = ' ';
 313         }
 314         return new String(hexView);
 315     }
 316 }
test/testlibrary/com/oracle/java/testlibrary/Utils.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File