Class StringElementSizer
java.lang.Object
uk.ac.starlink.votable.StringElementSizer
Object which is able to provide element sizes (string lengths)
for table columns containing String[] arrays.
This functionality is required when writing VOTable output; the FIELD headers need to have the common length of the strings, since VOTable output may contain variable-length arrays of fixed-length strings, but not fixed-length arrays of variable-length strings.
A number of implementations are provided. The basic approaches are to read all the elements and find the maximum string length, which in general requires an extra pass through the data, or just provide some sort of guess.
- Since:
- 19 Jun 2025
- Author:
- Mark Taylor
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringElementSizerIf called upon to provide length values, a false assertion is made.static final StringElementSizerIf called upon to provide length values, an error will be raised.static final StringElementSizerA fixed element length of 2 is used.static final StringElementSizerThe existing string length values, which may not be legal, are copied.static final StringElementSizerAll elements are read and the maximum length used.static final StringElementSizerThe first few elements are read and the maximum length used. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract int[]calculateStringArrayElementSizes(uk.ac.starlink.table.StarTable table, int[] icols) Fills in element length values for string array-valued columns in a supplied table.static StringElementSizercreateFixedSizer(int elSize) Creates an instance that reports a fixed length for all strings.static StringElementSizercreateSampleReadSizer(int maxRow) Creates an instance which reads some or all of the data to determine the maximum string length.
-
Field Details
-
NOCALC
The existing string length values, which may not be legal, are copied. -
READ
All elements are read and the maximum length used. -
SAMPLE
The first few elements are read and the maximum length used. -
FIXED2
A fixed element length of 2 is used. -
ERROR_IF_USED
If called upon to provide length values, an error will be raised. -
ASSERT_UNUSED
If called upon to provide length values, a false assertion is made.
-
-
Constructor Details
-
StringElementSizer
public StringElementSizer()
-
-
Method Details
-
calculateStringArrayElementSizes
public abstract int[] calculateStringArrayElementSizes(uk.ac.starlink.table.StarTable table, int[] icols) throws IOException Fills in element length values for string array-valued columns in a supplied table.The return value is an array the same size as the input
icolsarray whose elements are the calculated string lengths (ValueInfo.getElementSize()) for the corresponding column indices.- Parameters:
table- input tableicols- index array of String[]-valued columns whose element lengths need to be determined- Throws:
IOException
-
createFixedSizer
Creates an instance that reports a fixed length for all strings.- Parameters:
elSize- fixed string length- Returns:
- new sizer
-
createSampleReadSizer
Creates an instance which reads some or all of the data to determine the maximum string length.- Parameters:
maxRow- maximum number of rows to read; if not positive, all rows are read- Returns:
- new instance
-