类 AbstractFileItemWriter<T>
- java.lang.Object
- org.springframework.batch.item.ItemStreamSupport
- org.springframework.batch.item.support.AbstractItemStreamItemWriter<T>
- org.springframework.batch.item.support.AbstractFileItemWriter<T>
- 所有已实现的接口:
ResourceAwareItemWriterItemStream<T>,ItemStream,ItemStreamWriter<T>,ItemWriter<T>,org.springframework.beans.factory.InitializingBean
- 直接已知子类:
FlatFileItemWriter,JsonFileItemWriter
public abstract class AbstractFileItemWriter<T> extends AbstractItemStreamItemWriter<T> implements ResourceAwareItemWriterItemStream<T>, org.springframework.beans.factory.InitializingBean
Base class for item writers that write data to a file or stream. This class provides common features like restart, force sync, append etc. The location of the output file is defined by aResourcewhich must represent a writable file.
Uses buffered writer to improve performance.
The implementation is not thread-safe.- 从以下版本开始:
- 4.1
- 作者:
- Waseem Malik, Tomas Slanina, Robert Kasanicky, Dave Syer, Michael Minella, Mahmoud Ben Hassine
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected classAbstractFileItemWriter.OutputStateEncapsulates the runtime state of the writer.
字段概要
字段 修饰符和类型 字段 说明 protected booleanappendstatic java.lang.StringDEFAULT_CHARSETstatic java.lang.StringDEFAULT_LINE_SEPARATORstatic booleanDEFAULT_TRANSACTIONALprotected java.lang.StringlineSeparatorprotected static org.apache.commons.logging.Logloggerprotected booleanshouldDeleteIfExistsprotected AbstractFileItemWriter.OutputStatestate
构造器概要
构造器 构造器 说明 AbstractFileItemWriter()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 voidclose()No-op.protected abstract java.lang.StringdoWrite(java.util.List<? extends T> items)Write out a string of items followed by a "new line", where the format of the new line separator is determined by the underlying operating system.protected AbstractFileItemWriter.OutputStategetOutputState()voidopen(ExecutionContext executionContext)Initialize the reader.voidsetAppendAllowed(boolean append)Flag to indicate that the target file should be appended if it already exists.voidsetEncoding(java.lang.String newEncoding)Sets encoding for output template.voidsetFooterCallback(FlatFileFooterCallback footerCallback)footerCallback will be called after writing the last item to file, but before the file is closed.voidsetForceSync(boolean forceSync)Flag to indicate that changes should be force-synced to disk on flush.voidsetHeaderCallback(FlatFileHeaderCallback headerCallback)headerCallback will be called before writing the first item to file.voidsetLineSeparator(java.lang.String lineSeparator)Public setter for the line separator.voidsetResource(org.springframework.core.io.Resource resource)Setter for resource.voidsetSaveState(boolean saveState)Set the flag indicating whether or not state should be saved in the providedExecutionContextduring theItemStreamcall to update.voidsetShouldDeleteIfEmpty(boolean shouldDeleteIfEmpty)Flag to indicate that the target file should be deleted if no lines have been written (other than header and footer) on close.voidsetShouldDeleteIfExists(boolean shouldDeleteIfExists)Flag to indicate that the target file should be deleted if it already exists, otherwise it will be created.voidsetTransactional(boolean transactional)Flag to indicate that writing to the buffer should be delayed if a transaction is active.voidupdate(ExecutionContext executionContext)Return emptyExecutionContext.voidwrite(java.util.List<? extends T> items)Writes out a string followed by a "new line", where the format of the new line separator is determined by the underlying operating system.从类继承的方法 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
字段详细资料
DEFAULT_TRANSACTIONAL
public static final boolean DEFAULT_TRANSACTIONAL
- 另请参阅:
- 常量字段值
logger
protected static final org.apache.commons.logging.Log logger
DEFAULT_LINE_SEPARATOR
public static final java.lang.String DEFAULT_LINE_SEPARATOR
DEFAULT_CHARSET
public static final java.lang.String DEFAULT_CHARSET
- 另请参阅:
- 常量字段值
state
protected AbstractFileItemWriter.OutputState state
shouldDeleteIfExists
protected boolean shouldDeleteIfExists
lineSeparator
protected java.lang.String lineSeparator
append
protected boolean append
构造器详细资料
AbstractFileItemWriter
public AbstractFileItemWriter()
方法详细资料
setForceSync
public void setForceSync(boolean forceSync)
Flag to indicate that changes should be force-synced to disk on flush. Defaults to false, which means that even with a local disk changes could be lost if the OS crashes in between a write and a cache flush. Setting to true may result in slower performance for usage patterns involving many frequent writes.- 参数:
forceSync- the flag value to set
setLineSeparator
public void setLineSeparator(java.lang.String lineSeparator)
Public setter for the line separator. Defaults to the System property line.separator.- 参数:
lineSeparator- the line separator to set
setResource
public void setResource(org.springframework.core.io.Resource resource)
Setter for resource. Represents a file that can be written.- 指定者:
setResource在接口中ResourceAwareItemWriterItemStream<T>- 参数:
resource- the resource to be written to
setEncoding
public void setEncoding(java.lang.String newEncoding)
Sets encoding for output template.- 参数:
newEncoding-Stringcontaining the encoding to be used for the writer.
setShouldDeleteIfExists
public void setShouldDeleteIfExists(boolean shouldDeleteIfExists)
Flag to indicate that the target file should be deleted if it already exists, otherwise it will be created. Defaults to true, so no appending except on restart. If set to false andappendAllowedis also false then there will be an exception when the stream is opened to prevent existing data being potentially corrupted.- 参数:
shouldDeleteIfExists- the flag value to set
setAppendAllowed
public void setAppendAllowed(boolean append)
Flag to indicate that the target file should be appended if it already exists. If this flag is set then the flagshouldDeleteIfExistsis automatically set to false, so that flag should not be set explicitly. Defaults value is false.- 参数:
append- the flag value to set
setShouldDeleteIfEmpty
public void setShouldDeleteIfEmpty(boolean shouldDeleteIfEmpty)
Flag to indicate that the target file should be deleted if no lines have been written (other than header and footer) on close. Defaults to false.- 参数:
shouldDeleteIfEmpty- the flag value to set
setSaveState
public void setSaveState(boolean saveState)
Set the flag indicating whether or not state should be saved in the providedExecutionContextduring theItemStreamcall to update. Setting this to false means that it will always start at the beginning on a restart.- 参数:
saveState- if true, state will be persisted
setHeaderCallback
public void setHeaderCallback(FlatFileHeaderCallback headerCallback)
headerCallback will be called before writing the first item to file. Newline will be automatically appended after the header is written.- 参数:
headerCallback-FlatFileHeaderCallbackto generate the header
setFooterCallback
public void setFooterCallback(FlatFileFooterCallback footerCallback)
footerCallback will be called after writing the last item to file, but before the file is closed.- 参数:
footerCallback-FlatFileFooterCallbackto generate the footer
setTransactional
public void setTransactional(boolean transactional)
Flag to indicate that writing to the buffer should be delayed if a transaction is active. Defaults to true.- 参数:
transactional- true if writing to buffer should be delayed.
write
public void write(java.util.List<? extends T> items) throws java.lang.Exception
Writes out a string followed by a "new line", where the format of the new line separator is determined by the underlying operating system.- 指定者:
write在接口中ItemWriter<T>- 参数:
items- list of items to be written to output stream- 抛出:
java.lang.Exception- if an error occurs while writing items to the output stream
doWrite
protected abstract java.lang.String doWrite(java.util.List<? extends T> items)
Write out a string of items followed by a "new line", where the format of the new line separator is determined by the underlying operating system.- 参数:
items- to be written- 返回:
- written lines
close
public void close()
从类复制的说明:ItemStreamSupportNo-op.- 指定者:
close在接口中ItemStream- 覆盖:
close在类中ItemStreamSupport- 另请参阅:
ItemStream.close()
open
public void open(ExecutionContext executionContext) throws ItemStreamException
Initialize the reader. This method may be called multiple times before close is called.- 指定者:
open在接口中ItemStream- 覆盖:
open在类中ItemStreamSupport- 参数:
executionContext- current step'sExecutionContext. Will be the executionContext from the last run of the step on a restart.- 抛出:
ItemStreamException- 另请参阅:
ItemStream.open(ExecutionContext)
update
public void update(ExecutionContext executionContext)
从类复制的说明:ItemStreamSupportReturn emptyExecutionContext.- 指定者:
update在接口中ItemStream- 覆盖:
update在类中ItemStreamSupport- 参数:
executionContext- to be updated- 另请参阅:
ItemStream.update(ExecutionContext)
getOutputState
protected AbstractFileItemWriter.OutputState getOutputState()