package com.rle.monitor; import java.lang.*; import java.io.*; /* * RLE Surface Crack Detector Graphing Software * * Copyright (C) 2002 RLE Technologies * For more information visit http://www.rletech.com/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ /** * @author Andy Goth * @author Eric Peterson * @author Matt Lane * @version 0.1 */ /** String representation of the comma separated variable standard. */ public class CSVString { private StringBuffer buffer; /** Constructor. */ public CSVString() { super(); buffer = new StringBuffer(); } /** Returns the entire contents of the csv string. */ public String getCSVString() { return buffer.toString(); } /** Starts a new row. */ public void newRow() { buffer.append("\n"); } /** Adds a cell to the csv. */ public void addCell(int data) {addCell(String.valueOf(data));} /** Adds another cell into the csv. */ public void addCell(String data) { String copy = new String(data); copy.replace('"', '\''); if (data.indexOf(",") > -1) buffer.append("\"" + copy + "\","); else buffer.append(copy + ","); } /** Writes the csv to a text file. */ public void writeToFile(String fileName) throws IOException { File outputFile = new File(fileName); FileWriter out = new FileWriter(outputFile); out.write(getCSVString()); out.close(); } }