Package org.arakhne.afc.io.shape
Class AbstractCommonShapeFileWriter<E>
- java.lang.Object
-
- org.arakhne.afc.io.shape.AbstractCommonShapeFileWriter<E>
-
- Type Parameters:
E
- is the type of element to write inside the ESRI shape file.
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
AbstractShapeFileWriter
,ShapeFileIndexWriter
public abstract class AbstractCommonShapeFileWriter<E> extends Object implements AutoCloseable
This class permits to write an ESRI Shape file.The specification of the ESRI Shape file format is described in the July 98 specification document.
- 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:
- shapefile
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
BLOCK_SIZE
Size of a block of data in the buffer, when the seek feature was disable.
-
Constructor Summary
Constructors Constructor Description AbstractCommonShapeFileWriter(File shapeName, ShapeElementType elementType)
Constructor.AbstractCommonShapeFileWriter(OutputStream stream, ShapeElementType elementType)
Constructor.AbstractCommonShapeFileWriter(URL shapeName, ShapeElementType elementType)
Constructor.AbstractCommonShapeFileWriter(WritableByteChannel channel, ShapeElementType elementType)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
Flush temp buffers, write down final information in file header (file size...), and close the streams.protected void
ensureAvailableBytes(int amount)
Ensure that the reading buffer is containing enoug bytes to read.protected void
flush()
Force this writer to write the memory buffer inside the temporary file.ShapeElementType
getElementType()
Replies the type of the elements which will be written into the output stream.protected abstract ESRIBounds
getFileBounds()
Invoked to retrieve the bounds of the world.Progression
getTaskProgression()
Replies the task progression.protected boolean
isHeaderWritten()
Replies if the header was red.protected void
onHeaderWritten(ESRIBounds box, ShapeElementType type, Collection<? extends E> elements)
Invoked after the header was written.void
setTaskProgression(Progression progressBar)
Set the task progression associated to this writer.void
write(E element)
Write the Shape file and its associated files.void
write(Collection<? extends E> elements)
Write the Shape file and its associated files.protected void
writeBEDouble(double v)
Write a big endian 8-byte floating point number.protected void
writeBEInt(int v)
Write a big endian 4-byte integer.protected abstract void
writeElement(int recIndex, E element, ShapeElementType type)
Write an element inside the output stream.protected void
writeLEDouble(double v)
Write a little endian 8-byte floating point number.protected void
writeLEInt(int v)
Write a little endian 4-byte integer.
-
-
-
Field Detail
-
BLOCK_SIZE
protected static final int BLOCK_SIZE
Size of a block of data in the buffer, when the seek feature was disable.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractCommonShapeFileWriter
public AbstractCommonShapeFileWriter(File shapeName, ShapeElementType elementType) throws IOException
Constructor.- Parameters:
shapeName
- is the file to writeelementType
- is the type of the elements to write.- Throws:
IOException
- in case of error.
-
AbstractCommonShapeFileWriter
public AbstractCommonShapeFileWriter(URL shapeName, ShapeElementType elementType) throws IOException
Constructor.- Parameters:
shapeName
- is the file to writeelementType
- is the type of the elements to write.- Throws:
IOException
- in case of error.
-
AbstractCommonShapeFileWriter
public AbstractCommonShapeFileWriter(OutputStream stream, ShapeElementType elementType) throws IOException
Constructor.- Parameters:
stream
- is the file to writeelementType
- is the type of the elements to write.- Throws:
IOException
- in case of error.
-
AbstractCommonShapeFileWriter
public AbstractCommonShapeFileWriter(WritableByteChannel channel, ShapeElementType elementType) throws IOException
Constructor.- Parameters:
channel
- is the file to writeelementType
- is the type of the elements to write.- Throws:
IOException
- in case of error.
-
-
Method Detail
-
getElementType
public ShapeElementType getElementType()
Replies the type of the elements which will be written into the output stream.- Returns:
- the type of the written elements.
-
getTaskProgression
public Progression getTaskProgression()
Replies the task progression.- Returns:
- the task progression object associated to this writer, or
null
-
setTaskProgression
public void setTaskProgression(Progression progressBar)
Set the task progression associated to this writer.- Parameters:
progressBar
- is the task progression object associated to this writer, ornull
-
isHeaderWritten
protected boolean isHeaderWritten()
Replies if the header was red.- Returns:
true
if the header was red, otherwisefalse
-
flush
protected void flush() throws IOException
Force this writer to write the memory buffer inside the temporary file.- Throws:
IOException
- in case of error.
-
ensureAvailableBytes
protected void ensureAvailableBytes(int amount) throws IOException
Ensure that the reading buffer is containing enoug bytes to read.- Parameters:
amount
- is the count of expected bytes- Throws:
IOException
- in case of error.
-
writeBEInt
protected final void writeBEInt(int v) throws IOException
Write a big endian 4-byte integer.- Parameters:
v
- is a big endian 4-byte integer.- Throws:
IOException
- in case of error.
-
writeBEDouble
protected final void writeBEDouble(double v) throws IOException
Write a big endian 8-byte floating point number.- Parameters:
v
- is a big endian 8-byte floating point number.- Throws:
IOException
- in case of error.
-
writeLEInt
protected final void writeLEInt(int v) throws IOException
Write a little endian 4-byte integer.- Parameters:
v
- is a little endian 4-byte integer.- Throws:
IOException
- in case of error.
-
writeLEDouble
protected final void writeLEDouble(double v) throws IOException
Write a little endian 8-byte floating point number.- Parameters:
v
- is a little endian 8-byte floating point number.- Throws:
IOException
- in case of error.
-
onHeaderWritten
protected void onHeaderWritten(ESRIBounds box, ShapeElementType type, Collection<? extends E> elements) throws IOException
Invoked after the header was written.- Parameters:
box
- is the bouding box of the filetype
- is the type of the elements in the file.elements
- are the elements which are caused the header to be written.- Throws:
IOException
- in case of error.
-
close
public void close() throws IOException
Flush temp buffers, write down final information in file header (file size...), and close the streams.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- in case of error.
-
write
public final void write(E element) throws IOException
Write the Shape file and its associated files.- Parameters:
element
- is the elements to write down- Throws:
IOException
- in case of error.
-
write
public void write(Collection<? extends E> elements) throws IOException
Write the Shape file and its associated files.- Parameters:
elements
- are the elements to write down- Throws:
IOException
- in case of error.
-
writeElement
protected abstract void writeElement(int recIndex, E element, ShapeElementType type) throws IOException
Write an element inside the output stream.- Parameters:
recIndex
- is the index of the element in the file.element
- is the element to write.type
- is the expected type for the element.- Throws:
IOException
- in case of error.
-
getFileBounds
protected abstract ESRIBounds getFileBounds()
Invoked to retrieve the bounds of the world.- Returns:
- the bounds.
-
-