Path: blob/master/test/jdk/java/util/Properties/LoadParsing.java
41152 views
/*1* Copyright (c) 2018, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4115936 4385195 497229726* @summary checks for processing errors in properties.load27*/2829import java.io.File;30import java.io.FileInputStream;31import java.util.Properties;3233public class LoadParsing {34public static void main(String[] argv) throws Exception {35File f = new File(System.getProperty("test.src", "."), "input.txt");36FileInputStream myIn = new FileInputStream(f);37Properties myProps = new Properties();38int size = 0;39try {40myProps.load(myIn);41} finally {42myIn.close();43}4445if (!myProps.getProperty("key1").equals("value1"))46throw new RuntimeException("Bad comment parsing");47if (!myProps.getProperty("key2").equals("abc\\defg\\"))48throw new RuntimeException("Bad slash parsing");49if (!myProps.getProperty("key3").equals("value3"))50throw new RuntimeException("Adds spaces to key");51if (!myProps.getProperty("key4").equals(":value4"))52throw new RuntimeException("Bad separator parsing");53if (myProps.getProperty("#") != null)54throw new RuntimeException(55"Does not recognize comments with leading spaces");56if ((size=myProps.size()) != 4)57throw new RuntimeException(58"Wrong number of keys in Properties; expected 4, got " +59size + ".");60}61}626364