Package org.jgrapes.io
Class FileStorage
java.lang.Object
org.jgrapes.core.internal.ComponentVertex
org.jgrapes.core.Component
org.jgrapes.io.FileStorage
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
A component that reads from or writes to a file.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
-
Constructor Summary
ConstructorDescriptionFileStorage
(Channel channel) Create a new instance using the default buffer size of 8192.FileStorage
(Channel channel, int bufferSize) Create a new instance using the given size for the read buffers. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Handle close by closing the file associated with the channel.void
onInput
(Input<ByteBuffer> event, Channel channel) Handle input by writing it to the file, if a channel exists.void
onOutput
(Output<ByteBuffer> event, Channel channel) HandleOutput
events by writing them to the file, if a channel exists.void
onSaveInput
(SaveInput event) Opens a file for writing using the properties of the event.void
onSaveOutput
(SaveOutput event) Opens a file for writing using the properties of the event.void
Handle stop by closing all files.void
onStreamFile
(StreamFile event) Opens a file for reading using the properties of the event and streams its content as a sequence ofOutput
events with the end of record flag set in the last event.toString()
If a name has been set for this component (seeManager.setName(String)
), return the name, else return the object name provided byComponents.objectName(Object)
, usingComponentVertex.component()
as argument.Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
FileStorage
Create a new instance using the given size for the read buffers. -
FileStorage
Create a new instance using the default buffer size of 8192.
-
-
Method Details
-
onStreamFile
Opens a file for reading using the properties of the event and streams its content as a sequence ofOutput
events with the end of record flag set in the last event.All generated events are considered responses to this event and therefore fired using the event processor from the event’s I/O subchannel.
- Parameters:
event
- the event- Throws:
InterruptedException
- if the execution was interrupted
-
onSaveInput
Opens a file for writing using the properties of the event.All data from subsequent
Input
events is written to the file. The end of record flag is ignored.- Parameters:
event
- the event- Throws:
InterruptedException
- if the execution was interrupted
-
onInput
Handle input by writing it to the file, if a channel exists.- Parameters:
event
- the eventchannel
- the channel
-
onSaveOutput
Opens a file for writing using the properties of the event.All data from subsequent
Output
events is written to the file. The end of record flag is ignored.- Parameters:
event
- the event- Throws:
InterruptedException
- if the execution was interrupted
-
onOutput
HandleOutput
events by writing them to the file, if a channel exists.- Parameters:
event
- the eventchannel
- the channel
-
onClose
Handle close by closing the file associated with the channel.- Parameters:
event
- the eventchannel
- the channel- Throws:
InterruptedException
- the interrupted exception
-
onStop
Handle stop by closing all files.- Parameters:
event
- the event- Throws:
InterruptedException
- the interrupted exception
-
toString
Description copied from class:ComponentVertex
If a name has been set for this component (seeManager.setName(String)
), return the name, else return the object name provided byComponents.objectName(Object)
, usingComponentVertex.component()
as argument.- Overrides:
toString
in classComponentVertex
-