public class FileToken extends Object
e.g. Tokenize (read) File tsvFile = ... // input file FileToken fileToken = new FileToken(); fileToken.tokenize(new FileInputStream(tsvFile), resource -> { ... = resource.getHeaderInfo(); ... = resource.getValueList(); ... = resource.toColumnValueMap(); }, op -> op.delimitateByTab().encodeAsUTF8()); e.g. Make (write) File tsvFile = ... // output file List<String> columnNameList = ... // columns for header FileToken fileToken = new FileToken(); fileToken.make(new FileOutputStream(tsvFile), writer -> { for (Member member : ...) { // output data loop List<String> valueList = ...; // convert the member to the row resource writer.writeRow(valueList); // Yes, you write! } }, op -> op.delimitateByTab().encodeAsUTF8().headerInfo(columnNameList));
| 修飾子とタイプ | クラスと説明 |
|---|---|
static class |
FileToken.ValueLineInfo |
| 修飾子とタイプ | フィールドと説明 |
|---|---|
protected LineToken |
_lineToken
The handler of line token for help.
|
protected static String |
FIRST_LINE_DONE_MARK
The mark that means first line done for writing process.
|
protected static String |
HEADER_DONE_MARK
The mark that means header done for writing process.
|
| コンストラクタと説明 |
|---|
FileToken() |
protected static final String HEADER_DONE_MARK
protected static final String FIRST_LINE_DONE_MARK
protected final LineToken _lineToken
public void tokenize(String filePath, FileTokenizingCallback oneArgLambda, FileTokenOptionCall<FileTokenizingOption> opLambda) throws FileNotFoundException, IOException
File tsvFile = ... // input file FileToken fileToken = new FileToken(); fileToken.tokenize(new FileInputStream(tsvFile), resource -> { ... = resource.getHeaderInfo(); ... = resource.getValueList(); ... = resource.toColumnValueMap(); }, op -> op.delimitateByTab().encodeAsUTF8().handleEmptyAsNull());
filePath - The path of file name to read. (NotNull)oneArgLambda - The callback for file-tokenizing. (NotNull)opLambda - The callback for option for file-tokenizing. (NotNull, Required{delimiter, encoding})FileNotFoundException - When the file was not found.IOException - When the file reading failed.FileTokenizingSQLHandlingFailureException - When the SQL handling fails in the row handling process.protected FileTokenizingOption createFileTokenizingOption(FileTokenOptionCall<FileTokenizingOption> opLambda)
protected FileTokenizingOption newFileTokenizingOption()
public void tokenize(InputStream ins, FileTokenizingCallback oneArgLambda, FileTokenOptionCall<FileTokenizingOption> opLambda) throws FileNotFoundException, IOException
InputStreamReader and BufferedReader that wrap the stream. File tsvFile = ... // input file FileToken fileToken = new FileToken(); fileToken.tokenize(new FileInputStream(tsvFile), resource -> { ... = resource.getHeaderInfo(); ... = resource.getValueList(); }, op -> op.delimitateByTab().encodeAsUTF8().handleEmptyAsNull());
ins - The input stream for writing. This stream is closed after writing automatically. (NotNull)oneArgLambda - The callback for file-tokenizing. (NotNull)opLambda - The callback for option for file-tokenizing. (NotNull, Required{delimiter, encoding})FileNotFoundException - When the file was not found.IOException - When the file reading failed.FileTokenizingSQLHandlingFailureException - When the SQL handling fails in the row handling process.protected void doTokenize(InputStream ins, FileTokenizingCallback handlingCall, FileTokenOptionCall<FileTokenizingOption> opLambda) throws UnsupportedEncodingException, IOException
protected FileTokenizingRowResource createFileTokenizingRowResource()
protected String getTokenizedRestoredLineSeparator()
protected FileToken.ValueLineInfo arrangeValueList(String lineString, String delimiter)
protected FileToken.ValueLineInfo arrangeValueList(List<String> valueList, String delimiter)
protected FileToken.ValueLineInfo createValueLineInfo()
protected String connectPreString(String preString, String delimiter, String value)
protected boolean isNotBothQ(String value)
protected boolean isRearQOnly(String value)
protected boolean isFrontQOnly(String value)
protected boolean isQQ(String value)
protected boolean endsQuote(String value, boolean startsQuote)
protected boolean isOddNumber(int number)
protected FileTokenizingHeaderInfo analyzeHeaderInfo(String delimiter, String lineString)
protected FileTokenizingHeaderInfo createFileTokenizingHeaderInfo()
public void make(String filePath, FileMakingCallback oneArgLambda, FileTokenOptionCall<FileMakingOption> opLambda) throws FileNotFoundException, IOException
String tsvFile = ... // output file List<String> columnNameList = ... // columns for header FileToken fileToken = new FileToken(); fileToken.make(tsvFile, writer -> { for (Member member : ...) { // output data loop List<String> valueList = ...; // convert the member to the row resource writer.writeRow(valueList); // Yes, you write! } }, op -> op.delimitateByTab().encodeAsUTF8().headerInfo(columnNameList));
filePath - The path of token file to write. (NotNull)oneArgLambda - The callback for file-making with writer. (NotNull)opLambda - The callback for option for file-making. (NotNull, Required: delimiter, encoding)FileNotFoundException - When the file was not found.IOException - When the file writing failed.FileMakingInvalidValueCountException - When the value count of the row does not match column count of header.FileMakingSQLHandlingFailureException - When the SQL handling fails in the row writing process.protected void mkdirsIfNeeds(String filePath)
public void make(OutputStream ous, FileMakingCallback oneArgLambda, FileTokenOptionCall<FileMakingOption> opLambda) throws FileNotFoundException, IOException
OutputStreamWriter and BufferedWriter that wrap the stream. File tsvFile = ... // output file List<String> columnNameList = ... // columns for header FileToken fileToken = new FileToken(); fileToken.make(new FileOutputStream(tsvFile), writer -> { for (Member member : ...) { // output data loop List<String> valueList = ...; // convert the member to the row resource writer.writeRow(valueList); // Yes, you write! } }, op -> op.delimitateByTab().encodeAsUTF8().headerInfo(columnNameList));
ous - The output stream for writing. This stream is closed after writing automatically. (NotNull)oneArgLambda - The callback for file-making with writer. (NotNull)opLambda - The callback for option for file-making. (NotNull, Required: delimiter, encoding)FileNotFoundException - When the file was not found.IOException - When the file writing failed.FileMakingInvalidValueCountException - When the value count of the row does not match column count of header.FileMakingSQLHandlingFailureException - When the SQL handling fails in the row writing process.protected void doMake(OutputStream ous, FileMakingCallback handlingCall, FileTokenOptionCall<FileMakingOption> opLambda) throws FileNotFoundException, IOException
protected FileMakingOption createFileMakingOption(FileTokenOptionCall<FileMakingOption> opLambda)
protected FileMakingOption newFileMakingOption()
protected void doWriterHeader(Writer writer, List<String> columnNameList, FileMakingOption option, Set<String> doneMarkSet) throws IOException
IOExceptionprotected void callbackDataRowWriter(FileMakingCallback callback, FileMakingOption option, String lineSep, Writer writer, Set<String> doneMarkSet) throws IOException
IOExceptionprotected FileMakingRowResource createFileMakingRowResource()
protected void doWriteDataRow(Writer writer, FileMakingRowResource resource, FileMakingOption option, String lineSep, Set<String> doneMarkSet) throws IOException
IOExceptionprotected String prepareWritingLineSeparator(FileMakingOption option)
protected void prepareWritingLineOption(FileMakingOption option, LineMakingOption lineOp)
protected void reflectQuoteMinimally(FileMakingOption option, LineMakingOption lineOp)
protected void checkValueCount(FileMakingOption option, List<String> valueList)
protected void throwFileMakingInvalidValueCountException(List<String> columnNameList, List<String> valueList)
protected void assertMakingDelimiter(FileMakingOption option)
protected void assertMakingEncoding(FileMakingOption option)
Copyright © 2014–2015 The DBFlute Project. All rights reserved.