- java.lang.Object
-
- org.arakhne.afc.io.dbase.DBaseFileWriter
-
- All Implemented Interfaces:
AutoCloseable
public class DBaseFileWriter extends Object implements AutoCloseable
This class permits to write a dBase file.This class supports dBASE version 5. Version 7 specification is available at http://www.dbase.com/KnowledgeBase/int/db7_file_fmt.htm.
ESRi Limitations
Additionnally, this writer includes the ESRi restrictions on dBASE files. Shapefile feature attributes are stored in an associated .dbf file, and so attributes suffer a number of limitations.
Attribute names can only be up to 10 characters long. Longer names will be silently truncated. This may result in non-unique column names, which will definitely cause problems later. Starting with version 1.7, the OGR Shapefile driver tries to generate unique field names. Successive duplicate field names, including those created by truncation to 10 characters, will be truncated to 8 characters and appended with a serial number from 1 to 99.
Only Integer, Real, String and Date (not DateTime, just year/month/day) field types are supported. The various list, and binary field types cannot be created.
The field width and precision are directly used to establish storage size in the .dbf file. This means that strings longer than the field width, or numbers that don't fit into the indicated field format will suffer truncation.
Integer fields without an explicit width are treated as width 11.
Real (floating point) fields without an explicit width are treated as width 24 with 15 decimal places of precision.
String fields without an assigned width are treated as 80 characters.
Also, .dbf files are required to have at least one field. If none are created by the application an "FID" field will be automatically created and populated with the record number.
The OGR shapefile driver supports rewriting existing shapes in a shapefile as well as deleting shapes. Deleted shapes are marked for deletion in the .dbf file, and then ignored by OGR. To actually remove them permanently (resulting in renumbering of FIDs) invoke the SQL 'REPACK <tablename>' via the datasource ExecuteSQL() method.
- Since:
- 14.0
- Version:
- 17.0 2020-01-04 14:41:52
- Author:
- Stéphane GALLAND, Olivier LAMOTTE
- Maven Group Id:
- org.arakhne.afc.advanced
- Maven Artifact Id:
- dbasefile
-
-
Constructor Summary
Constructors Constructor Description DBaseFileWriter(File stream)
Constructor.DBaseFileWriter(OutputStream dbfStream)
Constructor.DBaseFileWriter(URL stream)
Constructor.DBaseFileWriter(WritableByteChannel channel)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the dBASE file.protected void
columnsSkipped(Set<String> skippedColumns)
Invoked each time a column was skipped by the writer because it does not support its output.DBaseCodePage
getCodePage()
Replies the output language to use in the dBASE file.static boolean
isSupportedType(DBaseFieldType type)
Replies if the given dBASE type is supported by this writer.void
setCodePage(DBaseCodePage code)
Replies the output language to use in the dBASE file.void
write(List<? extends AttributeProvider> providers)
Write the DBase file.void
write(AttributeProvider... providers)
Write the DBase file.void
writeHeader(List<? extends AttributeProvider> providers)
Write the header of the dbf file.void
writeHeader(AttributeProvider... providers)
Write the header of the dbf file.void
writeRecord(AttributeProvider element)
Write a record for attribute provider.
-
-
-
Constructor Detail
-
DBaseFileWriter
public DBaseFileWriter(File stream) throws IOException
Constructor.- Parameters:
stream
- is the file to write.- Throws:
IOException
- in case of error.
-
DBaseFileWriter
public DBaseFileWriter(URL stream) throws IOException
Constructor.- Parameters:
stream
- is the file to write.- Throws:
IOException
- in case of error.
-
DBaseFileWriter
public DBaseFileWriter(WritableByteChannel channel)
Constructor.- Parameters:
channel
- is the channel to write in.
-
DBaseFileWriter
public DBaseFileWriter(OutputStream dbfStream)
Constructor.- Parameters:
dbfStream
- is the output stream to use
-
-
Method Detail
-
getCodePage
public DBaseCodePage getCodePage()
Replies the output language to use in the dBASE file.- Returns:
- the output language to use in the dBASE file.
-
setCodePage
public void setCodePage(DBaseCodePage code)
Replies the output language to use in the dBASE file.- Parameters:
code
- the output language to use in the dBASE file.- Throws:
IllegalStateException
- if the header was already written.
-
isSupportedType
@Pure public static boolean isSupportedType(DBaseFieldType type)
Replies if the given dBASE type is supported by this writer.- Parameters:
type
- the type of the field.- Returns:
true
if the given type is supported by the writer, otherwisefalse
.- Since:
- 4.0
-
columnsSkipped
protected void columnsSkipped(Set<String> skippedColumns)
Invoked each time a column was skipped by the writer because it does not support its output.- Parameters:
skippedColumns
- are the skipped columns.- Since:
- 4.0
-
writeHeader
public void writeHeader(AttributeProvider... providers) throws IOException, AttributeException
Write the header of the dbf file.- Parameters:
providers
- is the list of attribute providers that will be used for the dbf writing.- Throws:
AttributeException
- if an attribute cannot pre set.IOException
- in case of IO error.
-
writeHeader
public void writeHeader(List<? extends AttributeProvider> providers) throws IOException, AttributeException
Write the header of the dbf file.- Parameters:
providers
- is the list of attribute providers that will be used for the dbf writing.- Throws:
AttributeException
- if an attribute cannot pre set.IOException
- in case of IO error.
-
writeRecord
public void writeRecord(AttributeProvider element) throws IOException, AttributeException
Write a record for attribute provider.- Parameters:
element
- is the element to write.- Throws:
AttributeException
- if an attribute cannot pre set.IOException
- in case of IO error.
-
write
public void write(AttributeProvider... providers) throws IOException, AttributeException
Write the DBase file.A call to this method is equivalent to the sequence of calls:
writeHeader(AttributeProvider[])
- foreach(providers)
writeRecord(AttributeProvider)
close()
- Parameters:
providers
- are the attribute container that must be written inside the dBASE file.- Throws:
AttributeException
- if an attribute cannot pre set.IOException
- in case of IO error.
-
write
public void write(List<? extends AttributeProvider> providers) throws IOException, AttributeException
Write the DBase file.A call to this method is equivalent to the sequence of calls:
writeHeader(AttributeProvider[])
- foreach(providers)
writeRecord(AttributeProvider)
close()
- Parameters:
providers
- are the attribute container that must be written inside the dBASE file.- Throws:
AttributeException
- if an attribute cannot pre set.IOException
- in case of IO error.
-
close
public void close() throws IOException
Close the dBASE file.This function writes the end of file character (1Ah).
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- in case of IO error.
-
-