Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Properties/CustomProvider.java
47182 views
/*1* Copyright (c) 2012, 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*/22/*23* @test24* @bug 800035425* @summary Test26* @compile -XDignore.symbol.file CustomProvider.java MyXmlPropertiesProvider.java27* @run main/othervm -Dsun.util.spi.XmlPropertiesProvider=MyXmlPropertiesProvider CustomProvider28*/2930import java.util.*;31import java.io.*;3233/**34* Sanity test to verify that the property sun.util.spi.XmlPropertiesProvider35* can be used to specify a custom provider for loading/storing properties36* in XML format.37*/38public class CustomProvider {3940public static void main(String[] args) throws IOException {41String provider = System.getProperty("sun.util.spi.XmlPropertiesProvider");42assertTrue(provider != null, "sun.util.spi.XmlPropertiesProvider not set");4344OutputStream out = new ByteArrayOutputStream();45InputStream in = new ByteArrayInputStream(new byte[100]);4647Properties props;4849props = new Properties();50props.loadFromXML(in);5152props = System.getProperties();53props.storeToXML(out, "comment");54props.storeToXML(out, "comment", "UTF-8");5556// check that the provider's load and store methods have been invoked5758assertTrue(MyXmlPropertiesProvider.createCount() == 1,59"Provider should only be created once");60assertTrue(MyXmlPropertiesProvider.loadCount() == 1,61"load method expected to be called once");62assertTrue(MyXmlPropertiesProvider.storeCount() == 2,63"store method expected to be called twice");64}6566static void assertTrue(boolean b, String msg) {67if (!b) throw new RuntimeException(msg);68}69}707172