Description
Compare contents of golden file with test output file line by line.
License
Open Source License
Parameter
Parameter | Description |
---|
goldfile | Golden output file name |
outputfile | Test output file name |
Exception
Parameter | Description |
---|
IOException | if an I/O error occurs reading from the file or amalformed or unmappable byte sequence is read. |
Return
true if two files are identical. false if two files are not identical.
Declaration
public static boolean compareWithGold(String goldfile, String outputfile) throws IOException
Method Source Code
//package com.java2s;
/*/*from w w w . j a va2 s . c o m*/
* Copyright (c) 2014, 2016, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
/**
* Compare contents of golden file with test output file line by line.
* return true if they're identical.
* @param goldfile Golden output file name
* @param outputfile Test output file name
* @return true if two files are identical.
* false if two files are not identical.
* @throws IOException if an I/O error occurs reading from the file or a
* malformed or unmappable byte sequence is read.
*/
public static boolean compareWithGold(String goldfile, String outputfile) throws IOException {
return compareWithGold(goldfile, outputfile, StandardCharsets.UTF_8);
}
/**
* Compare contents of golden file with test output file line by line.
* return true if they're identical.
* @param goldfile Golden output file name.
* @param outputfile Test output file name.
* @param cs the charset to use for decoding.
* @return true if two files are identical.
* false if two files are not identical.
* @throws IOException if an I/O error occurs reading from the file or a
* malformed or unmappable byte sequence is read.
*/
public static boolean compareWithGold(String goldfile, String outputfile, Charset cs) throws IOException {
boolean isSame = Files.readAllLines(Paths.get(goldfile))
.equals(Files.readAllLines(Paths.get(outputfile), cs));
if (!isSame) {
System.err.println("Golden file " + goldfile + " :");
Files.readAllLines(Paths.get(goldfile)).forEach(System.err::println);
System.err.println("Output file " + outputfile + " :");
Files.readAllLines(Paths.get(outputfile), cs).forEach(System.err::println);
}
return isSame;
}
}
Related
- asUTFString(byte[] content)
- backup(String inputFile, String backupFile)
- codeListToString(List utf8CodeList)
- codesToString(int[] utf8Codes)
- codeToString(int utf8Code)
- convertISO8859_1_to_UTF_8(String s)
- ConvertUTF8(byte[] buffer)
- createFileAndExport(String inputFileName, String outputFileName, String outputStr)
- createFromUTF8String(DatagramPacket packet, String str)