Path: blob/master/src/jdk.jcmd/share/classes/sun/tools/jstat/RawOutputFormatter.java
41159 views
/*1* Copyright (c) 2004, 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 sun.jvmstat.monitor.*;2930/**31* A class for formatting raw counter output.32*33* @author Brian Doherty34* @since 1.535*/36public class RawOutputFormatter implements OutputFormatter {37private List<Monitor> logged;38private String header;39private boolean printStrings;4041public RawOutputFormatter(List<Monitor> logged, boolean printStrings) {42this.logged = logged;43this.printStrings = printStrings;44}4546public String getHeader() throws MonitorException {47if (header == null) {48// build the header string and prune out any unwanted monitors49StringBuilder headerBuilder = new StringBuilder();50for (Iterator<Monitor> i = logged.iterator(); i.hasNext(); /* empty */ ) {51Monitor m = i.next();52headerBuilder.append(m.getName()).append(' ');53}54header = headerBuilder.toString();55}56return header;57}5859public String getRow() throws MonitorException {60StringBuilder row = new StringBuilder();61int count = 0;62for (Iterator<Monitor> i = logged.iterator(); i.hasNext(); /* empty */ ) {63Monitor m = i.next();64if (count++ > 0) {65row.append(" ");66}67if (printStrings && m instanceof StringMonitor) {68row.append("\"").append(m.getValue()).append("\"");69} else {70row.append(m.getValue());71}72}73return row.toString();74}75}767778