Path: blob/master/src/jdk.jcmd/share/classes/sun/tools/jstat/OptionFinder.java
41159 views
/*1* Copyright (c) 2004, 2010, 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*/2425package sun.tools.jstat;2627import java.util.*;28import java.net.*;29import java.io.*;3031/**32* A class for finding a specific special option in the jstat_options file.33*34* @author Brian Doherty35* @since 1.536*/37public class OptionFinder {3839private static final boolean debug = false;4041List<URL> optionsSources;4243public OptionFinder(List<URL> optionsSources) {44this.optionsSources = optionsSources;45}4647public OptionFormat getOptionFormat(String option, boolean useTimestamp) {48OptionFormat of = getOptionFormat(option, optionsSources);49OptionFormat tof = null;50if ((of != null) && (useTimestamp)) {51// prepend the timestamp column as first column52tof = getOptionFormat("timestamp", optionsSources);53if (tof != null) {54ColumnFormat cf = (ColumnFormat)tof.getSubFormat(0);55of.insertSubFormat(0, cf);56}57}58return of;59}6061protected OptionFormat getOptionFormat(String option, List<URL> sources) {62OptionFormat of = null;63for (URL u : sources) {64try {65Reader r = new BufferedReader(66new InputStreamReader(u.openStream()));67of = new Parser(r).parse(option);68if (of != null)69break;70} catch (IOException e) {71if (debug) {72System.err.println("Error processing " + u73+ " : " + e.getMessage());74e.printStackTrace();75}76} catch (ParserException e) {77// Exception in parsing the options file.78System.err.println(u + ": " + e.getMessage());79System.err.println("Parsing of " + u + " aborted");80}81}82return of;83}84}858687