001: /*
002: * @(#)AnalysisModuleIO.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.codecoverage.v2.datastore;
028:
029: import java.io.IOException;
030: import java.io.Reader;
031: import java.io.Writer;
032:
033: import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
034: import net.sourceforge.groboutils.codecoverage.v2.IMethodCode;
035:
036: /**
037: * Knows how to read and write an AnalysisModule object.
038: *
039: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
040: * @version $Date: 2004/04/15 05:48:26 $
041: * @since December 15, 2002
042: */
043: class AnalysisModuleIO {
044: public AnalysisModuleIO() {
045: // do nothing
046: }
047:
048: static class StaleAnalysisModule implements IAnalysisModule {
049: private String name;
050: private String unit;
051: private String mime;
052:
053: public StaleAnalysisModule(String n, String u, String m) {
054: this .name = n;
055: this .unit = u;
056: this .mime = m;
057: }
058:
059: public String getMeasureName() {
060: return this .name;
061: }
062:
063: public String getMeasureUnit() {
064: return this .unit;
065: }
066:
067: public String getMimeEncoding() {
068: return this .mime;
069: }
070:
071: public void analyze(IMethodCode method) {
072: throw new IllegalStateException(
073: "this is a stale module for measure '" + this .name
074: + "'");
075: }
076: }
077:
078: public void writeAnalysisModule(IAnalysisModule ams, Writer out)
079: throws IOException {
080: StringBuffer sb = new StringBuffer();
081:
082: sb.append(ams.getMeasureName().length()).append(':').append(
083: ams.getMeasureName()).append(',').append(
084: ams.getMeasureUnit().length()).append(':').append(
085: ams.getMeasureUnit()).append(',').append(
086: ams.getMimeEncoding().length()).append(':').append(
087: ams.getMimeEncoding());
088:
089: out.write(sb.toString());
090: }
091:
092: /**
093: * Does not read in the actual module, but a datastore that
094: * resembles the original.
095: */
096: public IAnalysisModule readAnalysisModule(Reader in)
097: throws IOException {
098: int count = ReadUtil.toInt(ReadUtil.readTo(in, ':'));
099: String measureName = ReadUtil.readCount(in, count);
100: ReadUtil.readTo(in, ',');
101:
102: count = ReadUtil.toInt(ReadUtil.readTo(in, ':'));
103: String measureUnit = ReadUtil.readCount(in, count);
104: ReadUtil.readTo(in, ',');
105:
106: count = ReadUtil.toInt(ReadUtil.readTo(in, ':'));
107: String mimeEncoding = ReadUtil.readCount(in, count);
108:
109: return new StaleAnalysisModule(measureName, measureUnit,
110: mimeEncoding);
111: }
112: }
|