InternalBuffer 유틸 메서드 추가
RecordParser 측에서 parse() 메서드 호출 시 [마지막 row, 일반 row, pos == limit] 경우의 수가 많기 때문에 이를 판단하여 전략을 반환하는 유틸 메서드 추가
class InternalBuffer
static <T, R> Optional<Function<T, R>> ifLastRowOrElse(InternalBuffer2 buffer,
Function<T, R> lastRowAction,
Function<T, R> otherAction) {
if (buffer.getPos() == buffer.getLimit()){
return Optional.empty();
}
boolean isLastLine = buffer.getState() == BufferState.LAST_LINE && buffer.getPos() < buffer.getLimit();
return Optional.of(isLastLine ? lastRowAction : otherAction);
}
Java
복사
class RecoredParser
@Override
public List<Record> parse(){
while (buffer.fill()){
Optional<Function<Object, Object>> parse =
InternalBuffer2.ifLastRowOrElse(buffer, this :: lastRowParse, this :: normalParse);
if (parse.isEmpty()){
break;
}
parse.get().apply(buffer);
}
}
/**
* lastRow의 경우는 pos 부터 limit까지 넘겨버리면 됨
* 어차피 row 단위로 하기때문에 row가 존재함은 무조건 보장됨
*
* normalParse -> return List<Record>
* boolean inQuote = false;
* int matchIndex = 0;
* char c = getCharAtBegin();
* if -> csvConfig.getQoute() == c
* inQuote = !inQuote
*
* if -> !inQuote && mathcIndex == 1
* fieldParser -> 넘김
* matchIndex = 0; 초기화
* buffer.newPos(buffer.getIncrementBegin());
* continue;
* buffer.incrementBegin();
*
*/
Java
복사