Skip to content

Commit

Permalink
Merge pull request #54 from alipay/20200710-bugfix
Browse files Browse the repository at this point in the history
20200710 bugfix
  • Loading branch information
quhongwei authored Jul 16, 2020
2 parents c195e55 + d8ef921 commit b57648f
Show file tree
Hide file tree
Showing 32 changed files with 1,032,486 additions and 106 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<url>https://github.com/alipay/rdf-file</url>

<properties>
<rdf.file.core.version>2.2.6</rdf.file.core.version>
<rdf.file.oss.version>2.2.6</rdf.file.oss.version>
<rdf.file.sftp.version>2.2.6</rdf.file.sftp.version>
<rdf.file.core.version>2.2.7</rdf.file.core.version>
<rdf.file.oss.version>2.2.7</rdf.file.oss.version>
<rdf.file.sftp.version>2.2.7</rdf.file.sftp.version>
</properties>

<modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
public class BodyCodec implements FileCodec {
public static BodyCodec instance = new BodyCodec();

/**
* @see hongwei.quhw.file.codec.FileCodec#serialize(Object, ProtocolFileWriter.quhw.file.common.CommonFileWriter)
*/
@Override
public void serialize(Object bean, FileConfig config, FileWriter writer,
Map<ProcessorTypeEnum, List<RdfFileProcessorSpi>> processors) {
Expand All @@ -56,9 +53,6 @@ public void serialize(Object bean, FileConfig config, FileWriter writer,
RowsCodec.serialize(bean, config, writer, processors, FileDataTypeEnum.BODY);
}

/**
* @see hongwei.quhw.file.codec.FileCodec#deserialize(ProtocolFileReader.quhw.file.common.CommonFileReader)
*/
@Override
public <T> T deserialize(Class<?> clazz, FileConfig config, FileReader reader,
Map<ProcessorTypeEnum, List<RdfFileProcessorSpi>> processors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
public class HeaderCodec implements FileCodec {
public static HeaderCodec instance = new HeaderCodec();

/**
* @see hongwei.quhw.file.codec.FileCodec#serialize(Object, hongwei.quhw.file.common.ProtocolFileWriter)
*/
@Override
public void serialize(Object bean, FileConfig config, FileWriter writer,
Map<ProcessorTypeEnum, List<RdfFileProcessorSpi>> processors) {
Expand All @@ -55,9 +52,6 @@ public void serialize(Object bean, FileConfig config, FileWriter writer,
RowsCodec.serialize(bean, config, writer, processors, FileDataTypeEnum.HEAD);
}

/**
* @see hongwei.quhw.file.codec.FileCodec#deserialize(hongwei.quhw.file.common.ProtocolFileReader)
*/
@Override
public <T> T deserialize(Class<?> clazz, FileConfig config, FileReader reader,
Map<ProcessorTypeEnum, List<RdfFileProcessorSpi>> processors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
public class TailCodec implements FileCodec {
public static TailCodec instance = new TailCodec();

/**
* @see hongwei.quhw.file.codec.FileCodec#serialize(Object, hongwei.quhw.file.common.ProtocolFileWriter)
*/
@Override
public void serialize(Object bean, FileConfig fileConfig, FileWriter writer,
Map<ProcessorTypeEnum, List<RdfFileProcessorSpi>> processors) {
Expand All @@ -54,9 +51,6 @@ public void serialize(Object bean, FileConfig fileConfig, FileWriter writer,
RowsCodec.serialize(bean, fileConfig, writer, processors, FileDataTypeEnum.TAIL);
}

/**
* @see hongwei.quhw.file.codec.FileCodec#deserialize(hongwei.quhw.file.common.ProtocolFileReader)
*/
@Override
public <T> T deserialize(Class<?> clazz, FileConfig fileConfig, FileReader reader,
Map<ProcessorTypeEnum, List<RdfFileProcessorSpi>> processors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ public void init(FileConfig fileConfig) {
}
}

/**
* @see hongwei.quhw.file.interfaces.FileWriter#writeHead(java.lang.Object)
*/
@Override
@Override
public void writeHead(Object headBean) {
ensureOpen();
HeaderCodec.instance.serialize(headBean, fileConfig, this, processors);
Expand All @@ -76,9 +73,6 @@ public void writeHead(Object headBean) {
new BizData(RdfFileConstants.DATA, headBean));
}

/**
* @see hongwei.quhw.file.interfaces.FileWriter#writeRow(java.lang.Object)
*/
@Override
public void writeRow(Object rowBean) {
ProcessExecutor.execute(ProcessorTypeEnum.BEFORE_WRITE_ROW, processors, fileConfig);
Expand All @@ -92,9 +86,6 @@ public void writeRow(Object rowBean) {
new BizData(RdfFileConstants.DATA, rowBean));
}

/**
* @see hongwei.quhw.file.interfaces.FileWriter#writeTail(java.lang.Object)
*/
@Override
public void writeTail(Object tailBean) {
ensureOpen();
Expand All @@ -105,9 +96,6 @@ public void writeTail(Object tailBean) {
new BizData(RdfFileConstants.DATA, tailBean));
}

/**
* @see hongwei.quhw.file.interfaces.FileWriter#close()
*/
@Override
public void close() {
close(true);
Expand Down Expand Up @@ -159,6 +147,7 @@ public Summary getSummary() {
public void append(InputStream in) {
RdfFileUtil.assertNotNull(in, "ProtocolFileWriter.append(inputsream == null) ",
RdfErrorEnum.ILLEGAL_ARGUMENT);
ensureOpen();
writer.append(in);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public Summary getSummary() {

@Override
public void append(InputStream in) {
ensureOpen();
writer.append(in);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@
public class AColumnFormat implements RdfFileFormatSpi {
private static final Pattern DIGITAL_REG = Pattern.compile("^[0-9]*$");

/**
* @see RdfFileFormatSpi.quhw.file.format.RdfFormat#serialize(java.lang.String, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
public String serialize(String field, FileColumnMeta columnMeta, FileConfig fileConfig) {
check(field, columnMeta);
return RdfFileUtil.alignLeftBlank(field, columnMeta.getRange().getFirstAttr(),
RdfFileUtil.getFileEncoding(fileConfig));
}

/**
* @see RdfFileFormatSpi.quhw.file.format.RdfFormat#deserialize(java.lang.String, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
public String deserialize(String field, FileColumnMeta columnMeta, FileConfig fileConfig) {
field = field.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@
*/
public class CColumnFormat implements RdfFileFormatSpi {

/**
* @see hongwei.quhw.file.format.RdfFileFormatSpi#serialize(java.lang.String, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
public String serialize(String field, FileColumnMeta columnMeta, FileConfig fileConfig) {
return RdfFileUtil.alignLeftBlank(field, columnMeta.getRange().getFirstAttr(),
RdfFileUtil.getFileEncoding(fileConfig));
}

/**
* @see hongwei.quhw.file.format.RdfFileFormatSpi#deserialize(java.lang.String, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
public String deserialize(String field, FileColumnMeta columnMeta, FileConfig fileConfig) {
return field.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
*/
public class CIfDefinedColumnFormat extends RawFormat implements RdfFileFormatSpi {

/**
* @see hongwei.quhw.file.format.RdfFileFormatSpi#serialize(java.lang.String, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
public String serialize(String field, FileColumnMeta columnMeta, FileConfig fileConfig) {
if (null != columnMeta.getRange()) {
Expand All @@ -39,9 +36,6 @@ public String serialize(String field, FileColumnMeta columnMeta, FileConfig file
return super.serialize(field, columnMeta, fileConfig);
}

/**
* @see hongwei.quhw.file.format.RdfFileFormatSpi#deserialize(java.lang.String, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
public String deserialize(String field, FileColumnMeta columnMeta, FileConfig fileConfig) {
return field.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
*/
public class NColumnFormat implements RdfFileFormatSpi {

/**
* @see hongwei.quhw.file.format.RdfFileFormatSpi#serialize(java.lang.String, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
public String serialize(String field, FileColumnMeta colMeta, FileConfig fileConfig) {
//空补零
Expand All @@ -39,12 +36,14 @@ public String serialize(String field, FileColumnMeta colMeta, FileConfig fileCon
} else {
try {
BigInteger value = new BigDecimal(field.toString().trim())
.multiply(new BigDecimal(
RdfFileUtil.alignLeft("1", colMeta.getRange().getSecondAttr() + 1, "0")))
.toBigInteger();
.multiply(new BigDecimal(RdfFileUtil.alignLeft("1", colMeta.getRange().getSecondAttr() + 1, "0"))).toBigInteger();

field = RdfFileUtil.alignRight(String.valueOf(value),
colMeta.getRange().getFirstAttr(), '0');
//负数
if (value.compareTo(new BigInteger("0")) < 0) {
field = RdfFileUtil.alignRight(String.valueOf(value.negate()), colMeta.getRange().getFirstAttr(), '0', true);
} else {
field = RdfFileUtil.alignRight(String.valueOf(value), colMeta.getRange().getFirstAttr(), '0');
}
} catch (NumberFormatException e) {
throw new RdfFileException("rdf-file#NColumnFormat field = " + field
+ ", columnName=" + colMeta.getName() + " 数组转换出错",
Expand All @@ -55,18 +54,13 @@ public String serialize(String field, FileColumnMeta colMeta, FileConfig fileCon
return field;
}

/**
* @see hongwei.quhw.file.format.RdfFileFormatSpi#deserialize(java.lang.String, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
public String deserialize(String field, FileColumnMeta colMeta, FileConfig fileConfig) {
//数值型补位为0 不可能StringUtils.isBlank(field)
BigDecimal value = null;
//有小数点
if (colMeta.getRange().getSecondAttr() > 0) {
value = new BigDecimal(field).divide(new BigDecimal(
RdfFileUtil.alignLeft("1", colMeta.getRange().getSecondAttr() + 1, "0")));

value = new BigDecimal(field).divide(new BigDecimal(RdfFileUtil.alignLeft("1", colMeta.getRange().getSecondAttr() + 1, "0")));
} else {
value = new BigDecimal(field);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@
*/
public class RawFormat implements RdfFileFormatSpi {

/**
* @see hongwei.quhw.file.format.RdfFileFormatSpi#serialize(java.lang.Object, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
public String serialize(String field, FileColumnMeta columnMeta, FileConfig fileConfig) {
return field;
}

/**
* @see hongwei.quhw.file.format.RdfFileFormatSpi#deserialize(java.lang.String, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
public String deserialize(String field, FileColumnMeta columnMeta, FileConfig fileConfig) {
return field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
*/
public class RowSplitByFixedlLength implements RdfFileRowSplitSpi {

/**
* @see RdfFileRowSplitSpi.quhw.file.split.RowSplit#split(java.lang.String, hongwei.quhw.file.meta.FileMeta)
*/
@Override
public String[] split(SplitContext ctx) {
FileMeta fileMeta = TemplateLoader.load(ctx.getFileConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
*/
public class RowSplitBySeparator implements RdfFileRowSplitSpi {

/**
* @see hongwei.quhw.file.split.RdfFileRowSplitSpi#split(java.lang.String, hongwei.quhw.file.meta.FileMeta)
*/
@Override
public String[] split(SplitContext ctx) {
String columnSplit = RdfFileUtil.getColumnSplit(ctx.getFileConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ protected String doDeserialize(String field, FileColumnMeta columnMeta) {
return field;
}

/**
* @see RdfFileColumnTypeSpi.quhw.file.type.ColumnTypeCodec#serialize(java.lang.Object, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
@Override
public String serialize(String field, FileColumnMeta columnMeta) {
String value = super.serialize(field, columnMeta);
check(value, columnMeta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ protected Double doDeserialize(String field, FileColumnMeta columnMeta) {
return Double.valueOf(field);
}

/**
* @see hongwei.quhw.file.type.RdfFileColumnTypeSpi#serialize(java.lang.Object, hongwei.quhw.file.meta.FileColumnMeta)
*/
@Override
public String serialize(Double field, FileColumnMeta columnMeta) {
return field.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ public static Object newInstance(String clazz) {
}
}

public static String alignRight(String str, int size, char padChar) {
return alignRight(str, size, padChar, false);
}

/**
* 基金格式中对数值补位
*
Expand All @@ -210,8 +214,18 @@ public static Object newInstance(String clazz) {
* @param padChar
* @return
*/
public static String alignRight(String str, int size, char padChar) {
String val = alignRight(str, size, String.valueOf(padChar));
public static String alignRight(String str, int size, char padChar, boolean negate) {
int alignSize = size;

if (negate) {
alignSize--;
}

String val = alignRight(str, alignSize, String.valueOf(padChar));

if (negate) {
val = "-" + val;
}

if (val.length() != size) {
throw new RdfFileException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public List<ProcessorTypeEnum> supportedTypes() {
return types;
}

/**
* @see hongwei.quhw.file.processor.RdfFileProcessorSpi#process(hongwei.quhw.file.processor.ProcessCotnext)
*/
@Override
public void process(ProcessCotnext pc) {
ProcessorTypeEnum processorType = pc.getProcessorType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public List<ProcessorTypeEnum> supportedTypes() {
return types;
}

/**
* @see hongwei.quhw.file.processor.RdfFileProcessorSpi#process(hongwei.quhw.file.processor.ProcessCotnext)
*/
@Override
public void process(ProcessCotnext pc) {
ProcessorTypeEnum processorType = pc.getProcessorType();
Expand Down
Loading

0 comments on commit b57648f

Please sign in to comment.