/*******************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.apache.kato.hprof;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.kato.hprof.datalayer.HProfFactory;
import org.apache.kato.hprof.datalayer.HProfFile;
import org.apache.kato.hprof.datalayer.IHProfRecord;
import org.apache.kato.hprof.datalayer.IUTF8HProfRecord;
public class HPROFUTF8Reporter {
private PrintStream out=System.out;
private Map<Integer,Counter> stats=new TreeMap<Integer,Counter>();
private TreeSet<String> labels=new TreeSet<String>();
/**
* @param args
*/
public static void main(String[] args) {
//File dump=new File("C:/Documents and Settings/spoole/workspace/HProf Binary Format Reader/data/java.hprof");
HPROFUTF8Reporter reporter=new HPROFUTF8Reporter();
File hprofFile=new File(args[0]);
try {
reporter.report(hprofFile);
} catch (IOException e) {
e.printStackTrace();
}
}
public void report(File dump) throws IOException {
HProfFile h=HProfFactory.createReader(dump);
h.open();
int counter=0;
while(true) {
IHProfRecord record=h.getRecord(counter);
if(record==null) break;
report(record);
counter++;
}
h.close();
}
private void report(IHProfRecord record) {
int tag=record.getTag();
switch(tag) {
case 0x01: IUTF8HProfRecord utf8Record=(IUTF8HProfRecord)record;
reportUTF8(utf8Record);
break;
}
}
private static String toHex(long v) {
return "0x"+Long.toHexString(v);
}
private void reportUTF8(IUTF8HProfRecord utf8Record) {
try {
String label=new String(utf8Record.getCharacters(),"UTF-8");
if(labels.contains(label)) {
int a=1;
}
out.println(label);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public HPROFUTF8Reporter() {
}
class Counter {
int count=0;
}
}