Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/non-build-utils/reorder/tools/Combine.java
32285 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/242526// Append files to one another without duplicating any lines.2728import java.io.BufferedReader;29import java.io.FileReader;30import java.util.HashMap;3132public class Combine {3334private static HashMap map = new HashMap(10007);3536private static void appendFile(String fileName, boolean keep) {37try {38BufferedReader br = new BufferedReader(new FileReader(fileName));3940// Read a line at a time. If the line does not appear in the41// hashmap, print it and add it to the hashmap, so that it will42// not be repeated.4344lineLoop:45while (true) {46String line = br.readLine();47if (line == null)48break;49if (keep || !map.containsKey(line)) {50System.out.println(line);51map.put(line,line);52}53}54br.close();55} catch (Exception e) {56e.printStackTrace();57System.exit(1);58}59}606162public static void main(String[] args) {6364if (args.length < 2) {65System.err.println("Usage: java Combine file1 file2 ...");66System.exit(2);67}6869for (int i = 0; i < args.length; ++i)70appendFile(args[i], i == 0);71}72}737475