@@ -212,6 +212,13 @@ private String readLine() { //NOPMD Bug in PMD
212212 final boolean isLastFilePart = partNumber == 1 ;
213213
214214 int i = currentLastBytePos ;
215+
216+ if (i == -1 && isLastFilePart && leftOver != null ) {
217+ line = new String (leftOver , charset );
218+ leftOver = null ;
219+ return line ;
220+ }
221+
215222 while (i > -1 ) {
216223
217224 if (!isLastFilePart && i < avoidNewlineSplitBufferSize ) {
@@ -234,6 +241,10 @@ private String readLine() { //NOPMD Bug in PMD
234241 line = new String (lineData , charset );
235242
236243 currentLastBytePos = i - newLineMatchByteCount ;
244+
245+ if (isLastFilePart && currentLastBytePos == -1 && i == 0 ) {
246+ leftOver = new byte [0 ];
247+ }
237248 break ; // found line
238249 }
239250
@@ -242,14 +253,22 @@ private String readLine() { //NOPMD Bug in PMD
242253
243254 // end of file part handling
244255 if (i < 0 ) {
245- createLeftOver ();
256+ if (isLastFilePart ) {
257+ final int lineLengthBytes = currentLastBytePos + 1 ;
258+ if (lineLengthBytes > 0 ) {
259+ final byte [] lineData = Arrays .copyOf (data , lineLengthBytes );
260+ line = new String (lineData , charset );
261+ }
262+ currentLastBytePos = -1 ;
263+ } else {
264+ createLeftOver ();
265+ }
246266 break ; // end of file part
247267 }
248268 }
249269
250- // last file part handling
251- if (isLastFilePart && leftOver != null ) {
252- // there will be partNumber line break anymore, this is the first line of the file
270+ // there will be partNumber line break anymore, this is the first line of the file
271+ if (line == null && isLastFilePart && leftOver != null ) {
253272 line = new String (leftOver , charset );
254273 leftOver = null ;
255274 }
0 commit comments