com.pmstation.spss
Class SPSSWriter

java.lang.Object
  extended by com.pmstation.spss.SPSSWriter
All Implemented Interfaces:
DataConstants

public class SPSSWriter
extends java.lang.Object
implements DataConstants

This class should be used to create a formatted data structure (in an SPSS format). It writes to defined output out SPSS stuctured data.

At first must be added dictionary section by calling addDictionarySection() method. Then it can be added a number of variable difinitions (the number of it should be lower than defined in addDictionarySection(). If method was called without this parameter definition it means that number of variables undefined).

After variable declaration there should be added a data section by calling addDataSection() method. Then can be added values of variable in the order of variable declaration (if there is wrong format type detecing method throws IOExceptin).

To finish data output should be called addFinishSection() method. In different order of method calling throws IOException.

Since:
JDK1.0
Version:
1.11, 07/28/03
Author:
Andrew Petrik from pmStation, Inc.
See Also:
OutputStream, Locale

Field Summary
 
Fields inherited from interface com.pmstation.spss.DataConstants
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, DATE_CODE_01, DATE_CODE_02, DATE_CODE_03, DATE_CODE_04, DATE_CODE_05, DATE_CODE_06, DATE_CODE_07, DATE_CODE_08, DATE_CODE_09, DATE_CODE_10, DATE_CODE_11, DATE_CODE_12, DATE_CODE_13, DATE_CODE_14, DATE_CODE_15, DATE_CODE_16, DATE_CODE_17, DATE_CODE_18, DATE_CODE_19, DATE_CODE_20, DATE_CODE_21, DATE_CODE_22, DATE_CODE_23, DATE_CODE_24, DATE_CODE_25, DATE_CODE_26, DATE_CODE_27, DATE_TYPE_01, DATE_TYPE_02, DATE_TYPE_03, DATE_TYPE_04, DATE_TYPE_05, DATE_TYPE_06, DATE_TYPE_07, DATE_TYPE_08, DATE_TYPE_09, DATE_TYPE_10, DATE_TYPE_11, DATE_TYPE_12, DATE_TYPE_13, DATE_TYPE_14, DATE_TYPE_15, DATE_TYPE_16, DATE_TYPE_17, DATE_TYPE_18, DATE_TYPE_19, DATE_TYPE_20, DATE_TYPE_21, DATE_TYPE_22, DATE_TYPE_23, DATE_TYPE_24, DATE_TYPE_25, DATE_TYPE_26, DATE_TYPE_27, MEASURE_NOMINAL, MEASURE_ORDINAL, MEASURE_SCALE
 
Constructor Summary
SPSSWriter(java.io.File file, java.lang.String charsetName)
          Constructs object based on an File object to write data in an SPSS format into a file.
SPSSWriter(java.io.OutputStream out, java.lang.String charsetName)
          Constructs object based on an OutputStream object to write data in an SPSS format into a stream.
SPSSWriter(java.lang.String fileName, java.lang.String charsetName)
          Constructs object that writes data in an SPSS format into a file.
 
Method Summary
 void addCommaVar(java.lang.String name, int width, int decimals, java.lang.String label)
          Add comma variable without formatting parameters to the variable list in dictionary section.
 void addCommaVar(java.lang.String name, int width, int decimals, java.lang.String label, int columns, int align, int measure)
          Add comma variable with formatting parameters to the variable list in dictionary section.
 void addData(java.util.Date data)
          Add new variable value to the current variable defined by currentVar variable that is internally increase in each data adding operation.
 void addData(java.lang.Double data)
          Add new variable value to the current variable defined by currentVar variable that is internally increase in each data adding operation.
 void addData(java.lang.Long data)
          Add new variable value to the current variable defined by currentVar variable that is internally increase in each data adding operation.
 void addData(java.lang.String data)
          Add new variable value to the current variable defined by currentVar variable that is internally increase in each data adding operation.
 void addDataSection()
          Write start of the data section (section of values of variables) into the defined in a constructor or with a setOut() method out.
 void addDateVar(java.lang.String name, int dateCode, java.lang.String label)
          Add date variable without formatting parameters to the variable list in dictionary section.
 void addDateVar(java.lang.String name, int dateCode, java.lang.String label, int columns, int align, int measure)
          Add date variable with formatting parameters to the variable list in dictionary section.
 void addDateVar(java.lang.String name, java.lang.String dateType, java.lang.String label)
          Add date variable without formatting parameters to the variable list in dictionary section.
 void addDateVar(java.lang.String name, java.lang.String dateType, java.lang.String label, int columns, int align, int measure)
          Add date variable with formatting parameters to the variable list in dictionary section.
 void addDictionarySection()
          Deprecated. use addDictionarySection(int numberOfCases) becouse of SPSS v14.0
 void addDictionarySection(int numberOfCases)
          Write start of the dictionary section (section of variable declaration) into the defined in a constructor or with a setOut() method out.
 void addDictionarySection(java.lang.String header, int numberOfVars, int numberOfCases, int caseWeightVar, int compressionSwitch, java.lang.String fileLabel, java.util.Date date, boolean storeFormat)
          Write start of the dictionary section (section of variable declaration) into the defined in a constructor or with a setOut() method out.
 void addDictionarySection(java.lang.String header, int numberOfVars, int numberOfCases, java.lang.String fileLabel, boolean storeFormat)
          Write start of the dictionary section (section of variable declaration) into the defined in a constructor or with a setOut() method out.
 void addDictionarySection(java.lang.String header, java.lang.String fileLabel)
          Write start of the dictionary section (section of variable declaration) into the defined in a constructor or with a setOut() method out.
 void addDollarVar(java.lang.String name, int width, int decimals, java.lang.String label)
          Add dollar variable without formatting parameters to the variable list in dictionary section.
 void addDollarVar(java.lang.String name, int width, int decimals, java.lang.String label, int columns, int align, int measure)
          Add dollar variable with formatting parameters to the variable list in dictionary section.
 void addDotVar(java.lang.String name, int width, int decimals, java.lang.String label)
          Add dot variable without formatting parameters to the variable list in dictionary section.
 void addDotVar(java.lang.String name, int width, int decimals, java.lang.String label, int columns, int align, int measure)
          Add dot variable with formatting parameters to the variable list in dictionary section.
 void addFinishSection()
          Write end of the data section (section of values of variables) and of all of the file into the defined in a constructor or with a setOut() method out.
 void addNumericVar(java.lang.String name, int width, int decimals, java.lang.String label)
          Add numeric variable without formatting parameters to the variable list in dictionary section.
 void addNumericVar(java.lang.String name, int width, int decimals, java.lang.String label, int columns, int align, int measure)
          Add numeric variable with formatting parameters to the variable list in dictionary section.
 void addNumericVar(java.lang.String name, int width, int decimals, java.lang.String label, int columns, int align, int measure, MissingValue mv)
          Add numeric variable with formatting parameters to the variable list in dictionary section.
 void addNumericVar(java.lang.String name, int width, int decimals, java.lang.String label, MissingValue mv)
          Add numeric variable without formatting parameters to the variable list in dictionary section.
 void addStringVar(java.lang.String name, int length, java.lang.String label)
          Add string variable without formatting parameters to the variable list in dictionary section.
 void addStringVar(java.lang.String name, int length, java.lang.String label, int columns, int align, int measure)
          Add string variable with formatting parameters to the variable list in dictionary section.
 void addValueLabels(int varNumber, ValueLabels valueLabels)
          Add value labels for variable number varNumber Note : Only for number variables
 void finishCurrentLine()
          Fills from current position to the end of current line with empty values.
 java.lang.String getCharset()
          Returns the value of the string format charset.
 java.io.OutputStream getOut()
          Returns the value of the stream that this object writes into as an OutputStream.
 void setCharset(java.lang.String charset)
          Set the charset name of the strings to out.
 void setOut(java.io.OutputStream out)
          Set the OutputStream object that this object writes into.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SPSSWriter

public SPSSWriter(java.lang.String fileName,
                  java.lang.String charsetName)
           throws java.lang.NullPointerException,
                  java.io.IOException
Constructs object that writes data in an SPSS format into a file.

Parameters:
fileName - name of the output file.
charsetName - the charset name or null if default.
Throws:
java.lang.NullPointerException - if the out parameter is null.
java.io.IOException

SPSSWriter

public SPSSWriter(java.io.File file,
                  java.lang.String charsetName)
           throws java.lang.NullPointerException,
                  java.io.IOException
Constructs object based on an File object to write data in an SPSS format into a file.

Parameters:
file - an File object to write into.
charsetName - the charset name or null if default.
Throws:
java.lang.NullPointerException - if the out parameter is null.
java.io.IOException

SPSSWriter

public SPSSWriter(java.io.OutputStream out,
                  java.lang.String charsetName)
           throws java.lang.NullPointerException
Constructs object based on an OutputStream object to write data in an SPSS format into a stream.

Parameters:
out - an OutputStream object to write into.
charsetName - the charset name or null if default.
Throws:
java.lang.NullPointerException - if the out parameter is null.
Method Detail

getOut

public java.io.OutputStream getOut()
Returns the value of the stream that this object writes into as an OutputStream.


setOut

public void setOut(java.io.OutputStream out)
            throws java.lang.NullPointerException
Set the OutputStream object that this object writes into. This method resets all of the predefined variables and its values.

Parameters:
out - the new OutputStream to write into.
Throws:
java.lang.NullPointerException - if the out parameter is null.

getCharset

public java.lang.String getCharset()
Returns the value of the string format charset.


setCharset

public void setCharset(java.lang.String charset)
Set the charset name of the strings to out.

Parameters:
charset - the new charset name or null if default.

addDictionarySection

public void addDictionarySection()
                          throws java.io.IOException
Deprecated. use addDictionarySection(int numberOfCases) becouse of SPSS v14.0

Write start of the dictionary section (section of variable declaration) into the defined in a constructor or with a setOut() method out.

Throws:
java.io.IOException - if defined OutputStream object unable to write to this out.

addDictionarySection

public void addDictionarySection(int numberOfCases)
                          throws java.io.IOException
Write start of the dictionary section (section of variable declaration) into the defined in a constructor or with a setOut() method out.

Parameters:
numberOfCases - number of cases (a block of a single values of the variables)
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDictionarySection

public void addDictionarySection(java.lang.String header,
                                 java.lang.String fileLabel)
                          throws java.io.IOException
Write start of the dictionary section (section of variable declaration) into the defined in a constructor or with a setOut() method out.

Parameters:
header - the header name of the file
fileLabel - discriptive label of the file
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDictionarySection

public void addDictionarySection(java.lang.String header,
                                 int numberOfVars,
                                 int numberOfCases,
                                 java.lang.String fileLabel,
                                 boolean storeFormat)
                          throws java.io.IOException
Write start of the dictionary section (section of variable declaration) into the defined in a constructor or with a setOut() method out.

Parameters:
header - the header name of the file
numberOfVars - number of variables
numberOfCases - number of cases (a block of a single values of the variables)
fileLabel - discriptive label of the file
storeFormat - true if there is a need to create a formatting section with a columns, align and measure fields.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDictionarySection

public void addDictionarySection(java.lang.String header,
                                 int numberOfVars,
                                 int numberOfCases,
                                 int caseWeightVar,
                                 int compressionSwitch,
                                 java.lang.String fileLabel,
                                 java.util.Date date,
                                 boolean storeFormat)
                          throws java.io.IOException
Write start of the dictionary section (section of variable declaration) into the defined in a constructor or with a setOut() method out.

Parameters:
header - the header name of the file
numberOfVars - number of variables
numberOfCases - number of cases (a block of a single values of the variables)
caseWeightVar - index of the case-weight variable
compressionSwitch - value of 0 - not compressed
fileLabel - discriptive label of the file
date - date of file creation or null if current
storeFormat - true if there is a need to create a formatting section with a columns, align and measure fields.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addNumericVar

public void addNumericVar(java.lang.String name,
                          int width,
                          int decimals,
                          java.lang.String label)
                   throws java.io.IOException
Add numeric variable without formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
width - number of the digits before point.
decimals - number of decimal digits after point.
label - label of the variable or null if there is no label.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addNumericVar

public void addNumericVar(java.lang.String name,
                          int width,
                          int decimals,
                          java.lang.String label,
                          MissingValue mv)
                   throws java.io.IOException
Add numeric variable without formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
width - number of the digits before point.
decimals - number of decimal digits after point.
label - label of the variable or null if there is no label.
mv - missing values
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addNumericVar

public void addNumericVar(java.lang.String name,
                          int width,
                          int decimals,
                          java.lang.String label,
                          int columns,
                          int align,
                          int measure)
                   throws java.io.IOException
Add numeric variable with formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
width - number of the digits before point.
decimals - number of decimal digits after point.
label - label of the variable or null if there is no label.
columns - number of columns to print variable value to display.
align - horizontal align of the variable value.
measure - the measure of this variable.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addNumericVar

public void addNumericVar(java.lang.String name,
                          int width,
                          int decimals,
                          java.lang.String label,
                          int columns,
                          int align,
                          int measure,
                          MissingValue mv)
                   throws java.io.IOException
Add numeric variable with formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
width - number of the digits before point.
decimals - number of decimal digits after point.
label - label of the variable or null if there is no label.
columns - number of columns to print variable value to display.
align - horizontal align of the variable value.
measure - the measure of this variable.
mv - missing values
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addCommaVar

public void addCommaVar(java.lang.String name,
                        int width,
                        int decimals,
                        java.lang.String label)
                 throws java.io.IOException
Add comma variable without formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
width - number of the digits before point.
decimals - number of decimal digits after point.
label - label of the variable or null if there is no label.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addCommaVar

public void addCommaVar(java.lang.String name,
                        int width,
                        int decimals,
                        java.lang.String label,
                        int columns,
                        int align,
                        int measure)
                 throws java.io.IOException
Add comma variable with formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
width - number of the digits before point.
decimals - number of decimal digits after point.
label - label of the variable or null if there is no label.
columns - number of columns to print variable value to display.
align - horizontal align of the variable value.
measure - the measure of this variable.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDotVar

public void addDotVar(java.lang.String name,
                      int width,
                      int decimals,
                      java.lang.String label)
               throws java.io.IOException
Add dot variable without formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
width - number of the digits before point.
decimals - number of decimal digits after point.
label - label of the variable or null if there is no label.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDotVar

public void addDotVar(java.lang.String name,
                      int width,
                      int decimals,
                      java.lang.String label,
                      int columns,
                      int align,
                      int measure)
               throws java.io.IOException
Add dot variable with formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
width - number of the digits before point.
decimals - number of decimal digits after point.
label - label of the variable or null if there is no label.
columns - number of columns to print variable value to display.
align - horizontal align of the variable value.
measure - the measure of this variable.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDollarVar

public void addDollarVar(java.lang.String name,
                         int width,
                         int decimals,
                         java.lang.String label)
                  throws java.io.IOException
Add dollar variable without formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
width - number of the digits before point.
decimals - number of decimal digits after point.
label - label of the variable or null if there is no label.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDollarVar

public void addDollarVar(java.lang.String name,
                         int width,
                         int decimals,
                         java.lang.String label,
                         int columns,
                         int align,
                         int measure)
                  throws java.io.IOException
Add dollar variable with formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
width - number of the digits before point.
decimals - number of decimal digits after point.
label - label of the variable or null if there is no label.
columns - number of columns to print variable value to display.
align - horizontal align of the variable value.
measure - the measure of this variable.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addStringVar

public void addStringVar(java.lang.String name,
                         int length,
                         java.lang.String label)
                  throws java.io.IOException
Add string variable without formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
length - maximum length of the value of this variable.
label - label of the variable or null if there is no label.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addStringVar

public void addStringVar(java.lang.String name,
                         int length,
                         java.lang.String label,
                         int columns,
                         int align,
                         int measure)
                  throws java.io.IOException
Add string variable with formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
length - maximum length of the value of this variable.
label - label of the variable or null if there is no label.
columns - number of columns to print variable value to display.
align - horizontal align of the variable value.
measure - the measure of this variable.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDateVar

public void addDateVar(java.lang.String name,
                       int dateCode,
                       java.lang.String label)
                throws java.io.IOException
Add date variable without formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
dateCode - some of the DATE_CODE_NN values that has a text interpretation in DATE_TYPE_NN constants.
label - label of the variable or null if there is no label.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDateVar

public void addDateVar(java.lang.String name,
                       int dateCode,
                       java.lang.String label,
                       int columns,
                       int align,
                       int measure)
                throws java.io.IOException
Add date variable with formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
dateCode - some of the DATE_CODE_NN values that has a text interpretation in DATE_TYPE_NN constants.
label - label of the variable or null if there is no label.
columns - number of columns to print variable value to display.
align - horizontal align of the variable value.
measure - the measure of this variable.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDateVar

public void addDateVar(java.lang.String name,
                       java.lang.String dateType,
                       java.lang.String label)
                throws java.io.IOException
Add date variable without formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
dateType - some of the DATE_TYPE_NN text interpretation constants.
label - label of the variable or null if there is no label.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDateVar

public void addDateVar(java.lang.String name,
                       java.lang.String dateType,
                       java.lang.String label,
                       int columns,
                       int align,
                       int measure)
                throws java.io.IOException
Add date variable with formatting parameters to the variable list in dictionary section.

Parameters:
name - the name of the variable.
dateType - some of the DATE_TYPE_NN text interpretation constants.
label - label of the variable or null if there is no label.
columns - number of columns to print variable value to display.
align - horizontal align of the variable value.
measure - the measure of this variable.
Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addDataSection

public void addDataSection()
                    throws java.io.IOException
Write start of the data section (section of values of variables) into the defined in a constructor or with a setOut() method out.

Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addData

public void addData(java.lang.Long data)
             throws java.io.IOException
Add new variable value to the current variable defined by currentVar variable that is internally increase in each data adding operation.

Parameters:
data - value of the current variable.
Throws:
java.io.IOException - if system unable to write to a stream or type of variable mismatches with a Long data type;

addData

public void addData(java.lang.Double data)
             throws java.io.IOException
Add new variable value to the current variable defined by currentVar variable that is internally increase in each data adding operation.

Parameters:
data - value of the current variable.
Throws:
java.io.IOException - if system unable to write to a stream or type of variable mismatches with a Double data type;

addData

public void addData(java.lang.String data)
             throws java.io.IOException
Add new variable value to the current variable defined by currentVar variable that is internally increase in each data adding operation.

Parameters:
data - value of the current variable.
Throws:
java.io.IOException - if system unable to write to a stream or type of variable mismatches with a String data type;

addData

public void addData(java.util.Date data)
             throws java.io.IOException
Add new variable value to the current variable defined by currentVar variable that is internally increase in each data adding operation.

Parameters:
data - value of the current variable.
Throws:
java.io.IOException - if system unable to write to a stream or type of variable mismatches with a Date data type;

finishCurrentLine

public void finishCurrentLine()
                       throws java.io.IOException
Fills from current position to the end of current line with empty values. If there is no items in the line (current position is the beginning), all the line filles.

Throws:
java.io.IOException - if system unable to write to a stream

addFinishSection

public void addFinishSection()
                      throws java.io.IOException
Write end of the data section (section of values of variables) and of all of the file into the defined in a constructor or with a setOut() method out.

Throws:
java.io.IOException - if defined OutputStream object unable to write data.

addValueLabels

public void addValueLabels(int varNumber,
                           ValueLabels valueLabels)
                    throws java.io.IOException
Add value labels for variable number varNumber Note : Only for number variables

Parameters:
varNumber - variable number, starts from 1
valueLabels - - ValueLabel object
Throws:
java.io.IOException


Copyright © 2003-2004 pmStation.com. All Rights Reserved.