001: /*
002: $Id: EjpFile.java,v 1.5 2005/02/22 12:50:08 vauclair Exp $
003:
004: Copyright (C) 2002-2005 Sebastien Vauclair
005:
006: This file is part of Extensible Java Profiler.
007:
008: Extensible Java Profiler is free software; you can redistribute it and/or
009: modify it under the terms of the GNU General Public License as published by
010: the Free Software Foundation; either version 2 of the License, or
011: (at your option) any later version.
012:
013: Extensible Java Profiler is distributed in the hope that it will be useful,
014: but WITHOUT ANY WARRANTY; without even the implied warranty of
015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: GNU General Public License for more details.
017:
018: You should have received a copy of the GNU General Public License
019: along with Extensible Java Profiler; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: */
022:
023: package ejp.presenter.parser;
024:
025: import java.io.File;
026: import java.text.ParseException;
027:
028: /**
029: * Holds information about a data file generated by EJP Tracer.
030: *
031: * @author Sebastien Vauclair
032: * @version <code>$Revision: 1.5 $<br>$Date: 2005/02/22 12:50:08 $</code>
033: */
034: public class EjpFile {
035: public static final String EJP_FILE_SUFFIX = ".ejp".toLowerCase();
036:
037: private static final char THREAD_INDEX_SEPARATOR = '-';
038:
039: private static final char SEPARATOR = '_';
040:
041: private static final String CLASSLOADER = "Classloader";
042:
043: private final File m_file;
044:
045: private final String m_timestamp;
046:
047: // private final long m_eventCount;
048:
049: private final String m_name;
050:
051: private final boolean m_classloader;
052:
053: public EjpFile(File f_) throws ParseException {
054: m_file = f_;
055:
056: String filename = f_.getName();
057:
058: // check suffix
059: if (!filename.toLowerCase().endsWith(EJP_FILE_SUFFIX)) {
060: throw new ParseException("Suffix was expected to be \""
061: + EJP_FILE_SUFFIX + "\"", -1);
062: }
063:
064: // remove suffix
065: filename = filename.substring(0, filename.length()
066: - EJP_FILE_SUFFIX.length());
067:
068: // check separator
069: int pos = filename.indexOf('_');
070: if (pos == -1) {
071: throw new ParseException("Missing '" + SEPARATOR
072: + "' separator", -1);
073: }
074:
075: // extract timestamp
076: m_timestamp = filename.substring(0, pos);
077: if (m_timestamp.length() == 0) {
078: throw new ParseException("Missing timestamp", -1);
079: }
080:
081: // extract name
082: m_name = filename.substring(pos + 1);
083: if (m_name.length() == 0) {
084: throw new ParseException("Missing name", -1);
085: }
086:
087: m_classloader = m_name.equals(CLASSLOADER);
088:
089: if (!m_classloader) {
090: pos = m_name.indexOf(THREAD_INDEX_SEPARATOR);
091: if (pos == -1) {
092: throw new ParseException("Missing '"
093: + THREAD_INDEX_SEPARATOR + "' separator", -1);
094: }
095:
096: pos = m_name.indexOf(SEPARATOR);
097: }
098:
099: // compute event count
100: // TODO reactivate? (need initial byte count)
101: // long size = f_.length();
102: // if (m_classloader)
103: // {
104: // m_eventCount = 0;
105: // }
106: // else
107: // {
108: // m_eventCount = (size - Constants.VERSION_SIZE) / Constants.ITEM_SIZE;
109: // }
110: }
111:
112: public File getClassloaderFile() {
113: return new File(m_file.getParentFile(), m_timestamp + SEPARATOR
114: + CLASSLOADER + EJP_FILE_SUFFIX);
115: }
116:
117: public File getFile() {
118: return m_file;
119: }
120:
121: public boolean isClassloader() {
122: return m_classloader;
123: }
124:
125: // /**
126: // * @return an undefined value iff this file is a classloader output.
127: // */
128: // public long getEventCount()
129: // {
130: // return m_eventCount;
131: // }
132:
133: public String getName() {
134: return m_name;
135: }
136:
137: public String getTimestamp() {
138: return m_timestamp;
139: }
140: }
|