Mega Code Archive
Data Text Writer
//** Copyright Statement ***************************************************
//The Salmon Open Framework for Internet Applications (SOFIA)
// Copyright (C) 1999 - 2002, Salmon LLC
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation;
//
// 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.
//
// For more information please visit http://www.salmonllc.com
//** End Copyright Statement ***************************************************
/////////////////////////
//$Archive: /JADE/SourceCode/com/salmonllc/util/DataTextWriter.java $
//$Author: Dan $
//$Revision: 7 $
//$Modtime: 10/30/02 2:59p $
/////////////////////////
import java.util.*;
import java.io.*;
/**
* This object allows you to write a flat text file with data elements separated by Separators and such.
*/
public class DataTextWriter {
private int NumColumns=0;
private Vector[] Columns;
private String LineBreak="\r\n";
private String Separator=",";
private boolean Quoted=false;
private char QuoteCharacter='\0';
private StringBuffer sbTextBuffer=new StringBuffer();
/**
* Builds a DataTextWriter with each row containing iNumColumns.
* @param iNumCols The number of columns in a row of the DataTextWriter.
*/
public DataTextWriter(int iNumCols) {
this(iNumCols,"","",'\0',false);
}
/**
* Builds a DataTextWriter with each row containing iNumCols and each piece of Data separated by sSeparator.
* @param iNumCols The number of columns in a row of the DataTextWriter.
* @param sSeparator The separator used to separate data columns in a row.
*/
public DataTextWriter(int iNumCols,String sSeparator) {
this(iNumCols,sSeparator,"",'\0',false);
}
/**
* Builds a DataTextWriter with each row containing iNumCols and each piece of Data separated by sSeparator
* and row separated by sLineBreak.
* @param iNumCols The number of columns in a row of the DataTextWriter.
* @param sSeparator The separator used to separate data columns in a row.
* @param sLineBreak The separator used to separate individual rows.
*/
public DataTextWriter(int iNumCols,String sSeparator,String sLineBreak) {
this(iNumCols,sSeparator,sLineBreak,'\0',false);
}
/**
* Builds a DataTextWriter with each row containing iNumColumns and each piece of Data separated by sSeparator
* and row separated by sLineBreak and each piece of Data is surrounded by cQuoteChar if bQuoted is true.
* @param iNumCols The number of columns in a row of the DataTextWriter.
* @param sSeparator The separator used to separate data columns in a row.
* @param sLineBreak The separator used to separate individual rows.
* @param cQuoteChar The character used to quote indivividual data columns.
* @param bQuoted The flag to indicate if data columns are to be quoted.
*/
public DataTextWriter(int iNumCols,String sSeparator,String sLineFeed,char cQuoteChar,boolean bQuoted) {
NumColumns=iNumCols;
Separator=sSeparator;
LineBreak=sLineFeed;
QuoteCharacter=cQuoteChar;
Quoted=bQuoted;
Columns=new Vector[iNumCols];
for (int i=0;i=NumColumns)
throw new Exception("Column Index is out of range. Valid Range is (0-"+(NumColumns-1)+").");
Columns[iColumn].addElement(sData);
int iCount=Columns[0].size();
for (int i=1;i