List of usage examples for org.springframework.batch.item.file.transform IncorrectLineLengthException IncorrectLineLengthException
public IncorrectLineLengthException(int expectedLength, int actualLength, String input)
From source file:egovframework.rte.bat.core.item.file.transform.EgovFixedLengthTokenizer.java
/** * String ? line? (ranges)? token ?. * // w w w . jav a2 s . c o m * @param String : ItemReader? ?? line * @return List<String> : tokens */ protected List<String> doTokenize(String line) { List<String> tokens = new ArrayList<String>(ranges.length); int lineLength; String token; lineLength = line.length(); if (lineLength == 0) { throw new IncorrectLineLengthException("Line length must be longer than 0", maxRange, lineLength); } if (lineLength < maxRange) { throw new IncorrectLineLengthException("Line is shorter than max range " + maxRange, maxRange, lineLength); } if (!open && lineLength > maxRange) { throw new IncorrectLineLengthException("Line is longer than max range " + maxRange, maxRange, lineLength); } for (int i = 0; i < ranges.length; i++) { int startPos = ranges[i].getMin() - 1; int endPos = ranges[i].getMax(); if (lineLength >= endPos) { token = line.substring(startPos, endPos); } else if (lineLength >= startPos) { token = line.substring(startPos); } else { token = ""; } tokens.add(token); } return tokens; }
From source file:egovframework.rte.bat.core.item.file.transform.EgovFixedByteLengthTokenizer.java
/** * ?? Encoding? ? ? ?? ? <code>line</code>. * /* w w w . j ava2s .c o m*/ * @param line * the line to be tokenised (can be <code>null</code>) * * @return the resulting tokens (empty if the line is null) * @throws IncorrectLineLengthException * if line length is greater than or less than the max range * set. */ protected List<String> doTokenize(String line, String encoding) throws Exception { List<String> tokens = new ArrayList<String>(ranges.length); String token; byte[] byteString = line.getBytes(encoding); int lineLength = byteString.length; if (lineLength == 0) { throw new IncorrectLineLengthException("Line length must be longer than 0", maxRange, lineLength); } if (lineLength < maxRange) { throw new IncorrectLineLengthException("Line is shorter than max range " + maxRange, maxRange, lineLength); } if (!open && lineLength > maxRange) { throw new IncorrectLineLengthException("Line is longer than max range " + maxRange, maxRange, lineLength); } for (int i = 0; i < ranges.length; i++) { int startPos = ranges[i].getMin() - 1; int endPos = ranges[i].getMax(); if (lineLength >= endPos) { token = new String(byteString, startPos, endPos - startPos, encoding); } else if (lineLength >= startPos) { token = new String(byteString, startPos, lineLength - startPos, encoding); } else { token = ""; } tokens.add(token); } return tokens; }
From source file:lcn.module.batch.core.item.file.transform.FixedByteTokenizer.java
/** * ?? Encoding? ? ? ?? ? <code>line</code>. * //from www . ja v a2s . com * @param line * the line to be tokenised (can be <code>null</code>) * * @return the resulting tokens (empty if the line is null) * @throws IncorrectLineLengthException * if line length is greater than or less than the max range * set. */ protected List<String> doTokenize(byte[] byteString, String encoding) throws Exception { String token; List<String> tokens = new ArrayList<String>(ranges.length); int lineLength = byteString.length - FlatFileByteReader.LINE_CRLF; if (lineLength == 0) { throw new IncorrectLineLengthException("Line length must be longer than 0", maxRange, lineLength); } if (lineLength < maxRange) { throw new IncorrectLineLengthException("Line is shorter than max range " + maxRange, maxRange, lineLength); } if (!open && lineLength > maxRange) { throw new IncorrectLineLengthException("Line is longer than max range " + maxRange, maxRange, lineLength); } for (int i = 0; i < ranges.length; i++) { int startPos = ranges[i].getMin() - 1; int endPos = ranges[i].getMax(); if (lineLength >= endPos) { token = new String(byteString, startPos, endPos - startPos, encoding); } else if (lineLength >= startPos) { token = new String(byteString, startPos, lineLength - startPos, encoding); } else { token = ""; } tokens.add(token); } return tokens; }
From source file:egovframework.rte.bat.core.item.file.transform.EgovFixedByteTokenizer.java
/** * ?? Encoding? ? ? ?? ? <code>line</code>. * //from ww w.ja v a2 s . com * @param line * the line to be tokenised (can be <code>null</code>) * * @return the resulting tokens (empty if the line is null) * @throws IncorrectLineLengthException * if line length is greater than or less than the max range * set. */ protected List<String> doTokenize(byte[] byteString, String encoding) throws Exception { String token; List<String> tokens = new ArrayList<String>(ranges.length); int lineLength = byteString.length - EgovFlatFileByteReader.LINE_CRLF; if (lineLength == 0) { throw new IncorrectLineLengthException("Line length must be longer than 0", maxRange, lineLength); } if (lineLength < maxRange) { throw new IncorrectLineLengthException("Line is shorter than max range " + maxRange, maxRange, lineLength); } if (!open && lineLength > maxRange) { throw new IncorrectLineLengthException("Line is longer than max range " + maxRange, maxRange, lineLength); } for (int i = 0; i < ranges.length; i++) { int startPos = ranges[i].getMin() - 1; int endPos = ranges[i].getMax(); if (lineLength >= endPos) { token = new String(byteString, startPos, endPos - startPos, encoding); } else if (lineLength >= startPos) { token = new String(byteString, startPos, lineLength - startPos, encoding); } else { token = ""; } tokens.add(token); } return tokens; }