embulk-input-filesplit 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +41 -40
  3. data/build.gradle +64 -64
  4. data/classpath/embulk-input-filesplit-0.1.4.jar +0 -0
  5. data/lib/embulk/input/filesplit.rb +3 -3
  6. data/src/main/java/org/embulk/input/filesplit/LocalFileSplitInputPlugin.java +300 -187
  7. data/src/test/java/org/embulk/input/filesplit/EmbulkPluginTester.java +70 -70
  8. data/src/test/java/org/embulk/input/filesplit/LocalFileSplitInputPluginTest.java +129 -94
  9. data/src/test/java/org/embulk/input/filesplit/LocalFileSplitInputTest.java +78 -78
  10. data/src/test/java/org/embulk/input/filesplit/PartialFileInputStreamTest.java +570 -570
  11. data/src/test/resources/data/sub1/test1.csv +1 -0
  12. data/src/test/resources/data/sub1/test2.csv +3 -0
  13. data/src/test/resources/data/sub2/test1.csv +1 -0
  14. data/src/test/resources/data/sub2/test2.csv +3 -0
  15. data/src/test/resources/data/sub2/x.csv +1 -0
  16. data/src/test/resources/data/test-header.csv +5 -5
  17. data/src/test/resources/data/test-semicolon.csv +4 -4
  18. data/src/test/resources/data/test.csv +4 -4
  19. data/src/test/resources/yml/test-error1.yml +22 -0
  20. data/src/test/resources/yml/test-error2.yml +24 -0
  21. data/src/test/resources/yml/test-header.yml +24 -24
  22. data/src/test/resources/yml/test-only-header.yml +24 -24
  23. data/src/test/resources/yml/test-path_prefix-directory.yml +23 -0
  24. data/src/test/resources/yml/test-path_prefix-files.yml +23 -0
  25. data/src/test/resources/yml/test-tasks.yml +23 -23
  26. data/src/test/resources/yml/test.yml +22 -22
  27. metadata +15 -6
  28. data/classpath/embulk-input-filesplit-0.1.3.jar +0 -0
@@ -1,570 +1,570 @@
1
- package org.embulk.input.filesplit;
2
-
3
- import java.io.ByteArrayInputStream;
4
- import java.io.IOException;
5
- import java.io.InputStream;
6
- import java.io.UnsupportedEncodingException;
7
-
8
- import org.junit.Test;
9
-
10
- import static org.junit.Assert.assertEquals;
11
-
12
- public class PartialFileInputStreamTest
13
- {
14
- private byte[] buffer = new byte[8];
15
-
16
- @Test
17
- public void testEmpty() throws IOException
18
- {
19
- try (InputStream in = createInput("", 0, 0)) {
20
- assertEquals(-1, in.read());
21
- }
22
- try (InputStream in = createInput("", 0, 0)) {
23
- assertEquals(-1, in.read(buffer));
24
- }
25
- }
26
-
27
- @Test
28
- public void testNoLineBreak() throws IOException
29
- {
30
- try (InputStream in = createInput("12345", 0, 4)) {
31
- assertEquals('1', in.read());
32
- assertEquals('2', in.read());
33
- assertEquals('3', in.read());
34
- assertEquals('4', in.read());
35
- assertEquals('5', in.read());
36
- assertEquals(-1, in.read());
37
- }
38
- try (InputStream in = createInput("12345", 0, 4)) {
39
- assertEquals(5, in.read(buffer));
40
- assertEquals('1', buffer[0]);
41
- assertEquals('2', buffer[1]);
42
- assertEquals('3', buffer[2]);
43
- assertEquals('4', buffer[3]);
44
- assertEquals('5', buffer[4]);
45
- }
46
-
47
- try (InputStream in = createInput("12345", 1, 4)) {
48
- assertEquals(-1, in.read());
49
- }
50
- try (InputStream in = createInput("12345", 1, 4)) {
51
- assertEquals(-1, in.read(buffer));
52
- }
53
- }
54
-
55
- @Test
56
- public void testLF() throws IOException
57
- {
58
- try (InputStream in = createInput("12345\n67\n89", 0, 4)) {
59
- assertEquals('1', in.read());
60
- assertEquals('2', in.read());
61
- assertEquals('3', in.read());
62
- assertEquals('4', in.read());
63
- assertEquals('5', in.read());
64
- assertEquals('\n', in.read());
65
- assertEquals(-1, in.read());
66
- }
67
- try (InputStream in = createInput("12345\n67\n89", 0, 4)) {
68
- assertEquals(6, in.read(buffer));
69
- assertEquals('1', buffer[0]);
70
- assertEquals('2', buffer[1]);
71
- assertEquals('3', buffer[2]);
72
- assertEquals('4', buffer[3]);
73
- assertEquals('5', buffer[4]);
74
- assertEquals('\n', buffer[5]);
75
- }
76
-
77
- try (InputStream in = createInput("12345\n67\n89", 1, 4)) {
78
- assertEquals(-1, in.read());
79
- }
80
- try (InputStream in = createInput("12345\n67\n89", 1, 4)) {
81
- assertEquals(-1, in.read(buffer));
82
- }
83
-
84
- try (InputStream in = createInput("12345\n67\n89", 1, 7)) {
85
- assertEquals('6', in.read());
86
- assertEquals('7', in.read());
87
- assertEquals('\n', in.read());
88
- assertEquals(-1, in.read());
89
- }
90
- try (InputStream in = createInput("12345\n67\n89", 1, 7)) {
91
- assertEquals(3, in.read(buffer));
92
- assertEquals('6', buffer[0]);
93
- assertEquals('7', buffer[1]);
94
- assertEquals('\n', buffer[2]);
95
- }
96
-
97
- try (InputStream in = createInput("12345\n67\n89", 1, 10)) {
98
- assertEquals('6', in.read());
99
- assertEquals('7', in.read());
100
- assertEquals('\n', in.read());
101
- assertEquals('8', in.read());
102
- assertEquals('9', in.read());
103
- assertEquals(-1, in.read());
104
- }
105
- try (InputStream in = createInput("12345\n67\n89", 1, 10)) {
106
- assertEquals(5, in.read(buffer));
107
- assertEquals('6', buffer[0]);
108
- assertEquals('7', buffer[1]);
109
- assertEquals('\n', buffer[2]);
110
- assertEquals('8', buffer[3]);
111
- assertEquals('9', buffer[4]);
112
- }
113
-
114
- try (InputStream in = createInput("12345\n67\n89", 10, 11)) {
115
- assertEquals(-1, in.read());
116
- }
117
- try (InputStream in = createInput("12345\n67\n89", 10, 11)) {
118
- assertEquals(-1, in.read(buffer));
119
- }
120
-
121
- // \nの直後まで
122
- try (InputStream in = createInput("12345\n67\n89", 4, 9)) {
123
- assertEquals('6', in.read());
124
- assertEquals('7', in.read());
125
- assertEquals('\n', in.read());
126
- assertEquals(-1, in.read());
127
- }
128
- try (InputStream in = createInput("12345\n67\n89", 4, 9)) {
129
- assertEquals(3, in.read(buffer));
130
- assertEquals('6', buffer[0]);
131
- assertEquals('7', buffer[1]);
132
- assertEquals('\n', buffer[2]);
133
- assertEquals(-1, in.read(buffer));
134
- }
135
- try (InputStream in = createInput("12345\n67\n89", 4, 9)) {
136
- assertEquals(3, in.read(buffer, 0, 3));
137
- assertEquals('6', buffer[0]);
138
- assertEquals('7', buffer[1]);
139
- assertEquals('\n', buffer[2]);
140
- assertEquals(-1, in.read(buffer));
141
- }
142
- // \nの直後から
143
- try (InputStream in = createInput("12345\n67\n89", 9, 11)) {
144
- assertEquals('8', in.read());
145
- assertEquals('9', in.read());
146
- assertEquals(-1, in.read());
147
- }
148
- try (InputStream in = createInput("12345\n67\n89", 9, 11)) {
149
- assertEquals(2, in.read(buffer));
150
- assertEquals('8', buffer[0]);
151
- assertEquals('9', buffer[1]);
152
- }
153
-
154
- // \nの直前まで
155
- try (InputStream in = createInput("12345\n67\n89", 4, 8)) {
156
- assertEquals('6', in.read());
157
- assertEquals('7', in.read());
158
- assertEquals('\n', in.read());
159
- assertEquals(-1, in.read());
160
- }
161
- try (InputStream in = createInput("12345\n67\n89", 4, 8)) {
162
- assertEquals(3, in.read(buffer));
163
- assertEquals('6', buffer[0]);
164
- assertEquals('7', buffer[1]);
165
- assertEquals('\n', buffer[2]);
166
- }
167
-
168
- // \nの直前から
169
- try (InputStream in = createInput("12345\n67\n89", 8, 11)) {
170
- assertEquals('8', in.read());
171
- assertEquals('9', in.read());
172
- assertEquals(-1, in.read());
173
- }
174
- try (InputStream in = createInput("12345\n67\n89", 8, 11)) {
175
- assertEquals(2, in.read(buffer));
176
- assertEquals('8', buffer[0]);
177
- assertEquals('9', buffer[1]);
178
- }
179
-
180
- // \nで終わる(最後まで)
181
- try (InputStream in = createInput("12345\n67\n", 5, 9)) {
182
- assertEquals('6', in.read());
183
- assertEquals('7', in.read());
184
- assertEquals('\n', in.read());
185
- assertEquals(-1, in.read());
186
- }
187
- try (InputStream in = createInput("12345\n67\n", 5, 9)) {
188
- assertEquals(3, in.read(buffer));
189
- assertEquals('6', buffer[0]);
190
- assertEquals('7', buffer[1]);
191
- assertEquals('\n', buffer[2]);
192
- }
193
-
194
- // \nで終わる(直前まで)
195
- try (InputStream in = createInput("12345\n67\n", 5, 8)) {
196
- assertEquals('6', in.read());
197
- assertEquals('7', in.read());
198
- assertEquals('\n', in.read());
199
- assertEquals(-1, in.read());
200
- }
201
- try (InputStream in = createInput("12345\n67\n", 5, 8)) {
202
- assertEquals(3, in.read(buffer));
203
- assertEquals('6', buffer[0]);
204
- assertEquals('7', buffer[1]);
205
- assertEquals('\n', buffer[2]);
206
- }
207
- }
208
-
209
-
210
- @Test
211
- public void testCRLF() throws IOException
212
- {
213
- try (InputStream in = createInput("12345\r\n67\r\n89", 0, 4)) {
214
- assertEquals('1', in.read());
215
- assertEquals('2', in.read());
216
- assertEquals('3', in.read());
217
- assertEquals('4', in.read());
218
- assertEquals('5', in.read());
219
- assertEquals('\r', in.read());
220
- assertEquals('\n', in.read());
221
- assertEquals(-1, in.read());
222
- }
223
- try (InputStream in = createInput("12345\r\n67\r\n89", 0, 4)) {
224
- assertEquals(7, in.read(buffer));
225
- assertEquals('1', buffer[0]);
226
- assertEquals('2', buffer[1]);
227
- assertEquals('3', buffer[2]);
228
- assertEquals('4', buffer[3]);
229
- assertEquals('5', buffer[4]);
230
- assertEquals('\r', buffer[5]);
231
- assertEquals('\n', buffer[6]);
232
- }
233
-
234
- try (InputStream in = createInput("12345\r\n67\r\n89", 1, 4)) {
235
- assertEquals(-1, in.read());
236
- }
237
- try (InputStream in = createInput("12345\r\n67\r\n89", 1, 4)) {
238
- assertEquals(-1, in.read(buffer));
239
- }
240
-
241
- try (InputStream in = createInput("12345\r\n67\r\n89", 1, 8)) {
242
- assertEquals('6', in.read());
243
- assertEquals('7', in.read());
244
- assertEquals('\r', in.read());
245
- assertEquals('\n', in.read());
246
- assertEquals(-1, in.read());
247
- }
248
- try (InputStream in = createInput("12345\r\n67\r\n89", 1, 8)) {
249
- assertEquals(4, in.read(buffer));
250
- assertEquals('6', buffer[0]);
251
- assertEquals('7', buffer[1]);
252
- assertEquals('\r', buffer[2]);
253
- assertEquals('\n', buffer[3]);
254
- }
255
-
256
- try (InputStream in = createInput("12345\r\n67\r\n89", 1, 12)) {
257
- assertEquals('6', in.read());
258
- assertEquals('7', in.read());
259
- assertEquals('\r', in.read());
260
- assertEquals('\n', in.read());
261
- assertEquals('8', in.read());
262
- assertEquals('9', in.read());
263
- assertEquals(-1, in.read());
264
- }
265
- try (InputStream in = createInput("12345\r\n67\r\n89", 1, 12)) {
266
- assertEquals(6, in.read(buffer));
267
- assertEquals('6', buffer[0]);
268
- assertEquals('7', buffer[1]);
269
- assertEquals('\r', buffer[2]);
270
- assertEquals('\n', buffer[3]);
271
- assertEquals('8', buffer[4]);
272
- assertEquals('9', buffer[5]);
273
- }
274
-
275
- try (InputStream in = createInput("12345\r\n67\r\n89", 12, 13)) {
276
- assertEquals(-1, in.read());
277
- }
278
- try (InputStream in = createInput("12345\r\n67\r\n89", 12, 13)) {
279
- assertEquals(-1, in.read(buffer));
280
- }
281
-
282
- // \nの直後まで
283
- try (InputStream in = createInput("12345\r\n67\r\n89", 4, 11)) {
284
- assertEquals('6', in.read());
285
- assertEquals('7', in.read());
286
- assertEquals('\r', in.read());
287
- assertEquals('\n', in.read());
288
- assertEquals(-1, in.read());
289
- }
290
- try (InputStream in = createInput("12345\r\n67\r\n89", 4, 11)) {
291
- assertEquals(4, in.read(buffer));
292
- assertEquals('6', buffer[0]);
293
- assertEquals('7', buffer[1]);
294
- assertEquals('\r', buffer[2]);
295
- assertEquals('\n', buffer[3]);
296
- assertEquals(-1, in.read(buffer));
297
- }
298
- try (InputStream in = createInput("12345\r\n67\r\n89", 4, 11)) {
299
- assertEquals(4, in.read(buffer, 0, 4));
300
- assertEquals('6', buffer[0]);
301
- assertEquals('7', buffer[1]);
302
- assertEquals('\r', buffer[2]);
303
- assertEquals('\n', buffer[3]);
304
- assertEquals(-1, in.read(buffer));
305
- }
306
- // \nの直後から
307
- try (InputStream in = createInput("12345\r\n67\r\n89", 11, 13)) {
308
- assertEquals('8', in.read());
309
- assertEquals('9', in.read());
310
- assertEquals(-1, in.read());
311
- }
312
- try (InputStream in = createInput("12345\r\n67\r\n89", 11, 13)) {
313
- assertEquals(2, in.read(buffer));
314
- assertEquals('8', buffer[0]);
315
- assertEquals('9', buffer[1]);
316
- }
317
-
318
- // \rと\nの間まで
319
- try (InputStream in = createInput("12345\r\n67\r\n89", 4, 10)) {
320
- assertEquals('6', in.read());
321
- assertEquals('7', in.read());
322
- assertEquals('\r', in.read());
323
- assertEquals('\n', in.read());
324
- assertEquals(-1, in.read());
325
- }
326
- try (InputStream in = createInput("12345\r\n67\r\n89", 4, 10)) {
327
- assertEquals(4, in.read(buffer));
328
- assertEquals('6', buffer[0]);
329
- assertEquals('7', buffer[1]);
330
- assertEquals('\r', buffer[2]);
331
- assertEquals('\n', buffer[3]);
332
- }
333
-
334
- // \rと\nの間から
335
- try (InputStream in = createInput("12345\r\n67\r\n89", 10, 13)) {
336
- assertEquals('8', in.read());
337
- assertEquals('9', in.read());
338
- assertEquals(-1, in.read());
339
- }
340
- try (InputStream in = createInput("12345\r\n67\r\n89", 10, 13)) {
341
- assertEquals(2, in.read(buffer));
342
- assertEquals('8', buffer[0]);
343
- assertEquals('9', buffer[1]);
344
- }
345
-
346
- // \rの直前まで
347
- try (InputStream in = createInput("12345\r\n67\r\n89", 4, 9)) {
348
- assertEquals('6', in.read());
349
- assertEquals('7', in.read());
350
- assertEquals('\r', in.read());
351
- assertEquals('\n', in.read());
352
- assertEquals(-1, in.read());
353
- }
354
- try (InputStream in = createInput("12345\r\n67\r\n89", 4, 9)) {
355
- assertEquals(4, in.read(buffer));
356
- assertEquals('6', buffer[0]);
357
- assertEquals('7', buffer[1]);
358
- assertEquals('\r', buffer[2]);
359
- assertEquals('\n', buffer[3]);
360
- }
361
-
362
- // \rの直前から
363
- try (InputStream in = createInput("12345\r\n67\r\n89", 9, 13)) {
364
- assertEquals('8', in.read());
365
- assertEquals('9', in.read());
366
- assertEquals(-1, in.read());
367
- }
368
- try (InputStream in = createInput("12345\r\n67\r\n89", 9, 13)) {
369
- assertEquals(2, in.read(buffer));
370
- assertEquals('8', buffer[0]);
371
- assertEquals('9', buffer[1]);
372
- }
373
-
374
- // \r\nで終わる(最後まで)
375
- try (InputStream in = createInput("12345\r\n67\r\n", 5, 11)) {
376
- assertEquals('6', in.read());
377
- assertEquals('7', in.read());
378
- assertEquals('\r', in.read());
379
- assertEquals('\n', in.read());
380
- assertEquals(-1, in.read());
381
- }
382
- try (InputStream in = createInput("12345\r\n67\r\n", 5, 11)) {
383
- assertEquals(4, in.read(buffer));
384
- assertEquals('6', buffer[0]);
385
- assertEquals('7', buffer[1]);
386
- assertEquals('\r', buffer[2]);
387
- assertEquals('\n', buffer[3]);
388
- }
389
-
390
- // \r\nで終わる(直前まで)
391
- try (InputStream in = createInput("12345\r\n67\r\n", 5, 10)) {
392
- assertEquals('6', in.read());
393
- assertEquals('7', in.read());
394
- assertEquals('\r', in.read());
395
- assertEquals('\n', in.read());
396
- assertEquals(-1, in.read());
397
- }
398
- try (InputStream in = createInput("12345\r\n67\r\n", 5, 10)) {
399
- assertEquals(4, in.read(buffer));
400
- assertEquals('6', buffer[0]);
401
- assertEquals('7', buffer[1]);
402
- assertEquals('\r', buffer[2]);
403
- assertEquals('\n', buffer[3]);
404
- }
405
- }
406
-
407
- @Test
408
- public void testCR() throws IOException
409
- {
410
- try (InputStream in = createInput("12345\r67\r89", 0, 4)) {
411
- assertEquals('1', in.read());
412
- assertEquals('2', in.read());
413
- assertEquals('3', in.read());
414
- assertEquals('4', in.read());
415
- assertEquals('5', in.read());
416
- assertEquals('\r', in.read());
417
- assertEquals(-1, in.read());
418
- }
419
- try (InputStream in = createInput("12345\r67\r89", 0, 4)) {
420
- assertEquals(6, in.read(buffer));
421
- assertEquals('1', buffer[0]);
422
- assertEquals('2', buffer[1]);
423
- assertEquals('3', buffer[2]);
424
- assertEquals('4', buffer[3]);
425
- assertEquals('5', buffer[4]);
426
- assertEquals('\r', buffer[5]);
427
- }
428
-
429
- try (InputStream in = createInput("12345\r67\r89", 1, 4)) {
430
- assertEquals(-1, in.read());
431
- }
432
- try (InputStream in = createInput("12345\r67\r89", 1, 4)) {
433
- assertEquals(-1, in.read(buffer));
434
- }
435
-
436
- try (InputStream in = createInput("12345\r67\r89", 1, 7)) {
437
- assertEquals('6', in.read());
438
- assertEquals('7', in.read());
439
- assertEquals('\r', in.read());
440
- assertEquals(-1, in.read());
441
- }
442
- try (InputStream in = createInput("12345\r67\r89", 1, 7)) {
443
- assertEquals(3, in.read(buffer));
444
- assertEquals('6', buffer[0]);
445
- assertEquals('7', buffer[1]);
446
- assertEquals('\r', buffer[2]);
447
- }
448
-
449
- try (InputStream in = createInput("12345\r67\r89", 1, 10)) {
450
- assertEquals('6', in.read());
451
- assertEquals('7', in.read());
452
- assertEquals('\r', in.read());
453
- assertEquals('8', in.read());
454
- assertEquals('9', in.read());
455
- assertEquals(-1, in.read());
456
- }
457
- try (InputStream in = createInput("12345\r67\r89", 1, 10)) {
458
- assertEquals(5, in.read(buffer));
459
- assertEquals('6', buffer[0]);
460
- assertEquals('7', buffer[1]);
461
- assertEquals('\r', buffer[2]);
462
- assertEquals('8', buffer[3]);
463
- assertEquals('9', buffer[4]);
464
- }
465
-
466
- try (InputStream in = createInput("12345\r67\r89", 10, 11)) {
467
- assertEquals(-1, in.read());
468
- }
469
- try (InputStream in = createInput("12345\r67\r89", 10, 11)) {
470
- assertEquals(-1, in.read(buffer));
471
- }
472
-
473
- // \rの直後まで
474
- try (InputStream in = createInput("12345\r67\r89", 4, 9)) {
475
- assertEquals('6', in.read());
476
- assertEquals('7', in.read());
477
- assertEquals('\r', in.read());
478
- assertEquals(-1, in.read());
479
- }
480
- try (InputStream in = createInput("12345\r67\r89", 4, 9)) {
481
- assertEquals(3, in.read(buffer));
482
- assertEquals('6', buffer[0]);
483
- assertEquals('7', buffer[1]);
484
- assertEquals('\r', buffer[2]);
485
- assertEquals(-1, in.read(buffer));
486
- }
487
- try (InputStream in = createInput("12345\r67\r89", 4, 9)) {
488
- assertEquals(3, in.read(buffer, 0, 3));
489
- assertEquals('6', buffer[0]);
490
- assertEquals('7', buffer[1]);
491
- assertEquals('\r', buffer[2]);
492
- assertEquals(-1, in.read(buffer));
493
- }
494
- // \rの直後から
495
- try (InputStream in = createInput("12345\r67\r89", 9, 11)) {
496
- assertEquals('8', in.read());
497
- assertEquals('9', in.read());
498
- assertEquals(-1, in.read());
499
- }
500
- try (InputStream in = createInput("12345\r67\r89", 9, 11)) {
501
- assertEquals(2, in.read(buffer));
502
- assertEquals('8', buffer[0]);
503
- assertEquals('9', buffer[1]);
504
- }
505
-
506
- // \rの直前まで
507
- try (InputStream in = createInput("12345\r67\r89", 4, 8)) {
508
- assertEquals('6', in.read());
509
- assertEquals('7', in.read());
510
- assertEquals('\r', in.read());
511
- assertEquals(-1, in.read());
512
- }
513
- try (InputStream in = createInput("12345\r67\r89", 4, 8)) {
514
- assertEquals(3, in.read(buffer));
515
- assertEquals('6', buffer[0]);
516
- assertEquals('7', buffer[1]);
517
- assertEquals('\r', buffer[2]);
518
- }
519
-
520
- // \rの直前から
521
- try (InputStream in = createInput("12345\r67\r89", 8, 11)) {
522
- assertEquals('8', in.read());
523
- assertEquals('9', in.read());
524
- assertEquals(-1, in.read());
525
- }
526
- try (InputStream in = createInput("12345\r67\r89", 8, 11)) {
527
- assertEquals(2, in.read(buffer));
528
- assertEquals('8', buffer[0]);
529
- assertEquals('9', buffer[1]);
530
- }
531
-
532
- // \rで終わる(最後まで)
533
- try (InputStream in = createInput("12345\r67\r", 5, 9)) {
534
- assertEquals('6', in.read());
535
- assertEquals('7', in.read());
536
- assertEquals('\r', in.read());
537
- assertEquals(-1, in.read());
538
- }
539
- try (InputStream in = createInput("12345\r67\r", 5, 9)) {
540
- assertEquals(3, in.read(buffer));
541
- assertEquals('6', buffer[0]);
542
- assertEquals('7', buffer[1]);
543
- assertEquals('\r', buffer[2]);
544
- }
545
-
546
- // \rで終わる(直前まで)
547
- try (InputStream in = createInput("12345\r67\r", 5, 8)) {
548
- assertEquals('6', in.read());
549
- assertEquals('7', in.read());
550
- assertEquals('\r', in.read());
551
- assertEquals(-1, in.read());
552
- }
553
- try (InputStream in = createInput("12345\r67\r", 5, 8)) {
554
- assertEquals(3, in.read(buffer));
555
- assertEquals('6', buffer[0]);
556
- assertEquals('7', buffer[1]);
557
- assertEquals('\r', buffer[2]);
558
- }
559
- }
560
-
561
- private InputStream createInput(String s, int start, int end)
562
- {
563
- try {
564
- return new PartialFileInputStream(new ByteArrayInputStream(s.getBytes("UTF-8")), start, end);
565
- } catch (UnsupportedEncodingException e) {
566
- throw new RuntimeException(e);
567
- }
568
- }
569
-
570
- }
1
+ package org.embulk.input.filesplit;
2
+
3
+ import java.io.ByteArrayInputStream;
4
+ import java.io.IOException;
5
+ import java.io.InputStream;
6
+ import java.io.UnsupportedEncodingException;
7
+
8
+ import org.junit.Test;
9
+
10
+ import static org.junit.Assert.assertEquals;
11
+
12
+ public class PartialFileInputStreamTest
13
+ {
14
+ private byte[] buffer = new byte[8];
15
+
16
+ @Test
17
+ public void testEmpty() throws IOException
18
+ {
19
+ try (InputStream in = createInput("", 0, 0)) {
20
+ assertEquals(-1, in.read());
21
+ }
22
+ try (InputStream in = createInput("", 0, 0)) {
23
+ assertEquals(-1, in.read(buffer));
24
+ }
25
+ }
26
+
27
+ @Test
28
+ public void testNoLineBreak() throws IOException
29
+ {
30
+ try (InputStream in = createInput("12345", 0, 4)) {
31
+ assertEquals('1', in.read());
32
+ assertEquals('2', in.read());
33
+ assertEquals('3', in.read());
34
+ assertEquals('4', in.read());
35
+ assertEquals('5', in.read());
36
+ assertEquals(-1, in.read());
37
+ }
38
+ try (InputStream in = createInput("12345", 0, 4)) {
39
+ assertEquals(5, in.read(buffer));
40
+ assertEquals('1', buffer[0]);
41
+ assertEquals('2', buffer[1]);
42
+ assertEquals('3', buffer[2]);
43
+ assertEquals('4', buffer[3]);
44
+ assertEquals('5', buffer[4]);
45
+ }
46
+
47
+ try (InputStream in = createInput("12345", 1, 4)) {
48
+ assertEquals(-1, in.read());
49
+ }
50
+ try (InputStream in = createInput("12345", 1, 4)) {
51
+ assertEquals(-1, in.read(buffer));
52
+ }
53
+ }
54
+
55
+ @Test
56
+ public void testLF() throws IOException
57
+ {
58
+ try (InputStream in = createInput("12345\n67\n89", 0, 4)) {
59
+ assertEquals('1', in.read());
60
+ assertEquals('2', in.read());
61
+ assertEquals('3', in.read());
62
+ assertEquals('4', in.read());
63
+ assertEquals('5', in.read());
64
+ assertEquals('\n', in.read());
65
+ assertEquals(-1, in.read());
66
+ }
67
+ try (InputStream in = createInput("12345\n67\n89", 0, 4)) {
68
+ assertEquals(6, in.read(buffer));
69
+ assertEquals('1', buffer[0]);
70
+ assertEquals('2', buffer[1]);
71
+ assertEquals('3', buffer[2]);
72
+ assertEquals('4', buffer[3]);
73
+ assertEquals('5', buffer[4]);
74
+ assertEquals('\n', buffer[5]);
75
+ }
76
+
77
+ try (InputStream in = createInput("12345\n67\n89", 1, 4)) {
78
+ assertEquals(-1, in.read());
79
+ }
80
+ try (InputStream in = createInput("12345\n67\n89", 1, 4)) {
81
+ assertEquals(-1, in.read(buffer));
82
+ }
83
+
84
+ try (InputStream in = createInput("12345\n67\n89", 1, 7)) {
85
+ assertEquals('6', in.read());
86
+ assertEquals('7', in.read());
87
+ assertEquals('\n', in.read());
88
+ assertEquals(-1, in.read());
89
+ }
90
+ try (InputStream in = createInput("12345\n67\n89", 1, 7)) {
91
+ assertEquals(3, in.read(buffer));
92
+ assertEquals('6', buffer[0]);
93
+ assertEquals('7', buffer[1]);
94
+ assertEquals('\n', buffer[2]);
95
+ }
96
+
97
+ try (InputStream in = createInput("12345\n67\n89", 1, 10)) {
98
+ assertEquals('6', in.read());
99
+ assertEquals('7', in.read());
100
+ assertEquals('\n', in.read());
101
+ assertEquals('8', in.read());
102
+ assertEquals('9', in.read());
103
+ assertEquals(-1, in.read());
104
+ }
105
+ try (InputStream in = createInput("12345\n67\n89", 1, 10)) {
106
+ assertEquals(5, in.read(buffer));
107
+ assertEquals('6', buffer[0]);
108
+ assertEquals('7', buffer[1]);
109
+ assertEquals('\n', buffer[2]);
110
+ assertEquals('8', buffer[3]);
111
+ assertEquals('9', buffer[4]);
112
+ }
113
+
114
+ try (InputStream in = createInput("12345\n67\n89", 10, 11)) {
115
+ assertEquals(-1, in.read());
116
+ }
117
+ try (InputStream in = createInput("12345\n67\n89", 10, 11)) {
118
+ assertEquals(-1, in.read(buffer));
119
+ }
120
+
121
+ // \nの直後まで
122
+ try (InputStream in = createInput("12345\n67\n89", 4, 9)) {
123
+ assertEquals('6', in.read());
124
+ assertEquals('7', in.read());
125
+ assertEquals('\n', in.read());
126
+ assertEquals(-1, in.read());
127
+ }
128
+ try (InputStream in = createInput("12345\n67\n89", 4, 9)) {
129
+ assertEquals(3, in.read(buffer));
130
+ assertEquals('6', buffer[0]);
131
+ assertEquals('7', buffer[1]);
132
+ assertEquals('\n', buffer[2]);
133
+ assertEquals(-1, in.read(buffer));
134
+ }
135
+ try (InputStream in = createInput("12345\n67\n89", 4, 9)) {
136
+ assertEquals(3, in.read(buffer, 0, 3));
137
+ assertEquals('6', buffer[0]);
138
+ assertEquals('7', buffer[1]);
139
+ assertEquals('\n', buffer[2]);
140
+ assertEquals(-1, in.read(buffer));
141
+ }
142
+ // \nの直後から
143
+ try (InputStream in = createInput("12345\n67\n89", 9, 11)) {
144
+ assertEquals('8', in.read());
145
+ assertEquals('9', in.read());
146
+ assertEquals(-1, in.read());
147
+ }
148
+ try (InputStream in = createInput("12345\n67\n89", 9, 11)) {
149
+ assertEquals(2, in.read(buffer));
150
+ assertEquals('8', buffer[0]);
151
+ assertEquals('9', buffer[1]);
152
+ }
153
+
154
+ // \nの直前まで
155
+ try (InputStream in = createInput("12345\n67\n89", 4, 8)) {
156
+ assertEquals('6', in.read());
157
+ assertEquals('7', in.read());
158
+ assertEquals('\n', in.read());
159
+ assertEquals(-1, in.read());
160
+ }
161
+ try (InputStream in = createInput("12345\n67\n89", 4, 8)) {
162
+ assertEquals(3, in.read(buffer));
163
+ assertEquals('6', buffer[0]);
164
+ assertEquals('7', buffer[1]);
165
+ assertEquals('\n', buffer[2]);
166
+ }
167
+
168
+ // \nの直前から
169
+ try (InputStream in = createInput("12345\n67\n89", 8, 11)) {
170
+ assertEquals('8', in.read());
171
+ assertEquals('9', in.read());
172
+ assertEquals(-1, in.read());
173
+ }
174
+ try (InputStream in = createInput("12345\n67\n89", 8, 11)) {
175
+ assertEquals(2, in.read(buffer));
176
+ assertEquals('8', buffer[0]);
177
+ assertEquals('9', buffer[1]);
178
+ }
179
+
180
+ // \nで終わる(最後まで)
181
+ try (InputStream in = createInput("12345\n67\n", 5, 9)) {
182
+ assertEquals('6', in.read());
183
+ assertEquals('7', in.read());
184
+ assertEquals('\n', in.read());
185
+ assertEquals(-1, in.read());
186
+ }
187
+ try (InputStream in = createInput("12345\n67\n", 5, 9)) {
188
+ assertEquals(3, in.read(buffer));
189
+ assertEquals('6', buffer[0]);
190
+ assertEquals('7', buffer[1]);
191
+ assertEquals('\n', buffer[2]);
192
+ }
193
+
194
+ // \nで終わる(直前まで)
195
+ try (InputStream in = createInput("12345\n67\n", 5, 8)) {
196
+ assertEquals('6', in.read());
197
+ assertEquals('7', in.read());
198
+ assertEquals('\n', in.read());
199
+ assertEquals(-1, in.read());
200
+ }
201
+ try (InputStream in = createInput("12345\n67\n", 5, 8)) {
202
+ assertEquals(3, in.read(buffer));
203
+ assertEquals('6', buffer[0]);
204
+ assertEquals('7', buffer[1]);
205
+ assertEquals('\n', buffer[2]);
206
+ }
207
+ }
208
+
209
+
210
+ @Test
211
+ public void testCRLF() throws IOException
212
+ {
213
+ try (InputStream in = createInput("12345\r\n67\r\n89", 0, 4)) {
214
+ assertEquals('1', in.read());
215
+ assertEquals('2', in.read());
216
+ assertEquals('3', in.read());
217
+ assertEquals('4', in.read());
218
+ assertEquals('5', in.read());
219
+ assertEquals('\r', in.read());
220
+ assertEquals('\n', in.read());
221
+ assertEquals(-1, in.read());
222
+ }
223
+ try (InputStream in = createInput("12345\r\n67\r\n89", 0, 4)) {
224
+ assertEquals(7, in.read(buffer));
225
+ assertEquals('1', buffer[0]);
226
+ assertEquals('2', buffer[1]);
227
+ assertEquals('3', buffer[2]);
228
+ assertEquals('4', buffer[3]);
229
+ assertEquals('5', buffer[4]);
230
+ assertEquals('\r', buffer[5]);
231
+ assertEquals('\n', buffer[6]);
232
+ }
233
+
234
+ try (InputStream in = createInput("12345\r\n67\r\n89", 1, 4)) {
235
+ assertEquals(-1, in.read());
236
+ }
237
+ try (InputStream in = createInput("12345\r\n67\r\n89", 1, 4)) {
238
+ assertEquals(-1, in.read(buffer));
239
+ }
240
+
241
+ try (InputStream in = createInput("12345\r\n67\r\n89", 1, 8)) {
242
+ assertEquals('6', in.read());
243
+ assertEquals('7', in.read());
244
+ assertEquals('\r', in.read());
245
+ assertEquals('\n', in.read());
246
+ assertEquals(-1, in.read());
247
+ }
248
+ try (InputStream in = createInput("12345\r\n67\r\n89", 1, 8)) {
249
+ assertEquals(4, in.read(buffer));
250
+ assertEquals('6', buffer[0]);
251
+ assertEquals('7', buffer[1]);
252
+ assertEquals('\r', buffer[2]);
253
+ assertEquals('\n', buffer[3]);
254
+ }
255
+
256
+ try (InputStream in = createInput("12345\r\n67\r\n89", 1, 12)) {
257
+ assertEquals('6', in.read());
258
+ assertEquals('7', in.read());
259
+ assertEquals('\r', in.read());
260
+ assertEquals('\n', in.read());
261
+ assertEquals('8', in.read());
262
+ assertEquals('9', in.read());
263
+ assertEquals(-1, in.read());
264
+ }
265
+ try (InputStream in = createInput("12345\r\n67\r\n89", 1, 12)) {
266
+ assertEquals(6, in.read(buffer));
267
+ assertEquals('6', buffer[0]);
268
+ assertEquals('7', buffer[1]);
269
+ assertEquals('\r', buffer[2]);
270
+ assertEquals('\n', buffer[3]);
271
+ assertEquals('8', buffer[4]);
272
+ assertEquals('9', buffer[5]);
273
+ }
274
+
275
+ try (InputStream in = createInput("12345\r\n67\r\n89", 12, 13)) {
276
+ assertEquals(-1, in.read());
277
+ }
278
+ try (InputStream in = createInput("12345\r\n67\r\n89", 12, 13)) {
279
+ assertEquals(-1, in.read(buffer));
280
+ }
281
+
282
+ // \nの直後まで
283
+ try (InputStream in = createInput("12345\r\n67\r\n89", 4, 11)) {
284
+ assertEquals('6', in.read());
285
+ assertEquals('7', in.read());
286
+ assertEquals('\r', in.read());
287
+ assertEquals('\n', in.read());
288
+ assertEquals(-1, in.read());
289
+ }
290
+ try (InputStream in = createInput("12345\r\n67\r\n89", 4, 11)) {
291
+ assertEquals(4, in.read(buffer));
292
+ assertEquals('6', buffer[0]);
293
+ assertEquals('7', buffer[1]);
294
+ assertEquals('\r', buffer[2]);
295
+ assertEquals('\n', buffer[3]);
296
+ assertEquals(-1, in.read(buffer));
297
+ }
298
+ try (InputStream in = createInput("12345\r\n67\r\n89", 4, 11)) {
299
+ assertEquals(4, in.read(buffer, 0, 4));
300
+ assertEquals('6', buffer[0]);
301
+ assertEquals('7', buffer[1]);
302
+ assertEquals('\r', buffer[2]);
303
+ assertEquals('\n', buffer[3]);
304
+ assertEquals(-1, in.read(buffer));
305
+ }
306
+ // \nの直後から
307
+ try (InputStream in = createInput("12345\r\n67\r\n89", 11, 13)) {
308
+ assertEquals('8', in.read());
309
+ assertEquals('9', in.read());
310
+ assertEquals(-1, in.read());
311
+ }
312
+ try (InputStream in = createInput("12345\r\n67\r\n89", 11, 13)) {
313
+ assertEquals(2, in.read(buffer));
314
+ assertEquals('8', buffer[0]);
315
+ assertEquals('9', buffer[1]);
316
+ }
317
+
318
+ // \rと\nの間まで
319
+ try (InputStream in = createInput("12345\r\n67\r\n89", 4, 10)) {
320
+ assertEquals('6', in.read());
321
+ assertEquals('7', in.read());
322
+ assertEquals('\r', in.read());
323
+ assertEquals('\n', in.read());
324
+ assertEquals(-1, in.read());
325
+ }
326
+ try (InputStream in = createInput("12345\r\n67\r\n89", 4, 10)) {
327
+ assertEquals(4, in.read(buffer));
328
+ assertEquals('6', buffer[0]);
329
+ assertEquals('7', buffer[1]);
330
+ assertEquals('\r', buffer[2]);
331
+ assertEquals('\n', buffer[3]);
332
+ }
333
+
334
+ // \rと\nの間から
335
+ try (InputStream in = createInput("12345\r\n67\r\n89", 10, 13)) {
336
+ assertEquals('8', in.read());
337
+ assertEquals('9', in.read());
338
+ assertEquals(-1, in.read());
339
+ }
340
+ try (InputStream in = createInput("12345\r\n67\r\n89", 10, 13)) {
341
+ assertEquals(2, in.read(buffer));
342
+ assertEquals('8', buffer[0]);
343
+ assertEquals('9', buffer[1]);
344
+ }
345
+
346
+ // \rの直前まで
347
+ try (InputStream in = createInput("12345\r\n67\r\n89", 4, 9)) {
348
+ assertEquals('6', in.read());
349
+ assertEquals('7', in.read());
350
+ assertEquals('\r', in.read());
351
+ assertEquals('\n', in.read());
352
+ assertEquals(-1, in.read());
353
+ }
354
+ try (InputStream in = createInput("12345\r\n67\r\n89", 4, 9)) {
355
+ assertEquals(4, in.read(buffer));
356
+ assertEquals('6', buffer[0]);
357
+ assertEquals('7', buffer[1]);
358
+ assertEquals('\r', buffer[2]);
359
+ assertEquals('\n', buffer[3]);
360
+ }
361
+
362
+ // \rの直前から
363
+ try (InputStream in = createInput("12345\r\n67\r\n89", 9, 13)) {
364
+ assertEquals('8', in.read());
365
+ assertEquals('9', in.read());
366
+ assertEquals(-1, in.read());
367
+ }
368
+ try (InputStream in = createInput("12345\r\n67\r\n89", 9, 13)) {
369
+ assertEquals(2, in.read(buffer));
370
+ assertEquals('8', buffer[0]);
371
+ assertEquals('9', buffer[1]);
372
+ }
373
+
374
+ // \r\nで終わる(最後まで)
375
+ try (InputStream in = createInput("12345\r\n67\r\n", 5, 11)) {
376
+ assertEquals('6', in.read());
377
+ assertEquals('7', in.read());
378
+ assertEquals('\r', in.read());
379
+ assertEquals('\n', in.read());
380
+ assertEquals(-1, in.read());
381
+ }
382
+ try (InputStream in = createInput("12345\r\n67\r\n", 5, 11)) {
383
+ assertEquals(4, in.read(buffer));
384
+ assertEquals('6', buffer[0]);
385
+ assertEquals('7', buffer[1]);
386
+ assertEquals('\r', buffer[2]);
387
+ assertEquals('\n', buffer[3]);
388
+ }
389
+
390
+ // \r\nで終わる(直前まで)
391
+ try (InputStream in = createInput("12345\r\n67\r\n", 5, 10)) {
392
+ assertEquals('6', in.read());
393
+ assertEquals('7', in.read());
394
+ assertEquals('\r', in.read());
395
+ assertEquals('\n', in.read());
396
+ assertEquals(-1, in.read());
397
+ }
398
+ try (InputStream in = createInput("12345\r\n67\r\n", 5, 10)) {
399
+ assertEquals(4, in.read(buffer));
400
+ assertEquals('6', buffer[0]);
401
+ assertEquals('7', buffer[1]);
402
+ assertEquals('\r', buffer[2]);
403
+ assertEquals('\n', buffer[3]);
404
+ }
405
+ }
406
+
407
+ @Test
408
+ public void testCR() throws IOException
409
+ {
410
+ try (InputStream in = createInput("12345\r67\r89", 0, 4)) {
411
+ assertEquals('1', in.read());
412
+ assertEquals('2', in.read());
413
+ assertEquals('3', in.read());
414
+ assertEquals('4', in.read());
415
+ assertEquals('5', in.read());
416
+ assertEquals('\r', in.read());
417
+ assertEquals(-1, in.read());
418
+ }
419
+ try (InputStream in = createInput("12345\r67\r89", 0, 4)) {
420
+ assertEquals(6, in.read(buffer));
421
+ assertEquals('1', buffer[0]);
422
+ assertEquals('2', buffer[1]);
423
+ assertEquals('3', buffer[2]);
424
+ assertEquals('4', buffer[3]);
425
+ assertEquals('5', buffer[4]);
426
+ assertEquals('\r', buffer[5]);
427
+ }
428
+
429
+ try (InputStream in = createInput("12345\r67\r89", 1, 4)) {
430
+ assertEquals(-1, in.read());
431
+ }
432
+ try (InputStream in = createInput("12345\r67\r89", 1, 4)) {
433
+ assertEquals(-1, in.read(buffer));
434
+ }
435
+
436
+ try (InputStream in = createInput("12345\r67\r89", 1, 7)) {
437
+ assertEquals('6', in.read());
438
+ assertEquals('7', in.read());
439
+ assertEquals('\r', in.read());
440
+ assertEquals(-1, in.read());
441
+ }
442
+ try (InputStream in = createInput("12345\r67\r89", 1, 7)) {
443
+ assertEquals(3, in.read(buffer));
444
+ assertEquals('6', buffer[0]);
445
+ assertEquals('7', buffer[1]);
446
+ assertEquals('\r', buffer[2]);
447
+ }
448
+
449
+ try (InputStream in = createInput("12345\r67\r89", 1, 10)) {
450
+ assertEquals('6', in.read());
451
+ assertEquals('7', in.read());
452
+ assertEquals('\r', in.read());
453
+ assertEquals('8', in.read());
454
+ assertEquals('9', in.read());
455
+ assertEquals(-1, in.read());
456
+ }
457
+ try (InputStream in = createInput("12345\r67\r89", 1, 10)) {
458
+ assertEquals(5, in.read(buffer));
459
+ assertEquals('6', buffer[0]);
460
+ assertEquals('7', buffer[1]);
461
+ assertEquals('\r', buffer[2]);
462
+ assertEquals('8', buffer[3]);
463
+ assertEquals('9', buffer[4]);
464
+ }
465
+
466
+ try (InputStream in = createInput("12345\r67\r89", 10, 11)) {
467
+ assertEquals(-1, in.read());
468
+ }
469
+ try (InputStream in = createInput("12345\r67\r89", 10, 11)) {
470
+ assertEquals(-1, in.read(buffer));
471
+ }
472
+
473
+ // \rの直後まで
474
+ try (InputStream in = createInput("12345\r67\r89", 4, 9)) {
475
+ assertEquals('6', in.read());
476
+ assertEquals('7', in.read());
477
+ assertEquals('\r', in.read());
478
+ assertEquals(-1, in.read());
479
+ }
480
+ try (InputStream in = createInput("12345\r67\r89", 4, 9)) {
481
+ assertEquals(3, in.read(buffer));
482
+ assertEquals('6', buffer[0]);
483
+ assertEquals('7', buffer[1]);
484
+ assertEquals('\r', buffer[2]);
485
+ assertEquals(-1, in.read(buffer));
486
+ }
487
+ try (InputStream in = createInput("12345\r67\r89", 4, 9)) {
488
+ assertEquals(3, in.read(buffer, 0, 3));
489
+ assertEquals('6', buffer[0]);
490
+ assertEquals('7', buffer[1]);
491
+ assertEquals('\r', buffer[2]);
492
+ assertEquals(-1, in.read(buffer));
493
+ }
494
+ // \rの直後から
495
+ try (InputStream in = createInput("12345\r67\r89", 9, 11)) {
496
+ assertEquals('8', in.read());
497
+ assertEquals('9', in.read());
498
+ assertEquals(-1, in.read());
499
+ }
500
+ try (InputStream in = createInput("12345\r67\r89", 9, 11)) {
501
+ assertEquals(2, in.read(buffer));
502
+ assertEquals('8', buffer[0]);
503
+ assertEquals('9', buffer[1]);
504
+ }
505
+
506
+ // \rの直前まで
507
+ try (InputStream in = createInput("12345\r67\r89", 4, 8)) {
508
+ assertEquals('6', in.read());
509
+ assertEquals('7', in.read());
510
+ assertEquals('\r', in.read());
511
+ assertEquals(-1, in.read());
512
+ }
513
+ try (InputStream in = createInput("12345\r67\r89", 4, 8)) {
514
+ assertEquals(3, in.read(buffer));
515
+ assertEquals('6', buffer[0]);
516
+ assertEquals('7', buffer[1]);
517
+ assertEquals('\r', buffer[2]);
518
+ }
519
+
520
+ // \rの直前から
521
+ try (InputStream in = createInput("12345\r67\r89", 8, 11)) {
522
+ assertEquals('8', in.read());
523
+ assertEquals('9', in.read());
524
+ assertEquals(-1, in.read());
525
+ }
526
+ try (InputStream in = createInput("12345\r67\r89", 8, 11)) {
527
+ assertEquals(2, in.read(buffer));
528
+ assertEquals('8', buffer[0]);
529
+ assertEquals('9', buffer[1]);
530
+ }
531
+
532
+ // \rで終わる(最後まで)
533
+ try (InputStream in = createInput("12345\r67\r", 5, 9)) {
534
+ assertEquals('6', in.read());
535
+ assertEquals('7', in.read());
536
+ assertEquals('\r', in.read());
537
+ assertEquals(-1, in.read());
538
+ }
539
+ try (InputStream in = createInput("12345\r67\r", 5, 9)) {
540
+ assertEquals(3, in.read(buffer));
541
+ assertEquals('6', buffer[0]);
542
+ assertEquals('7', buffer[1]);
543
+ assertEquals('\r', buffer[2]);
544
+ }
545
+
546
+ // \rで終わる(直前まで)
547
+ try (InputStream in = createInput("12345\r67\r", 5, 8)) {
548
+ assertEquals('6', in.read());
549
+ assertEquals('7', in.read());
550
+ assertEquals('\r', in.read());
551
+ assertEquals(-1, in.read());
552
+ }
553
+ try (InputStream in = createInput("12345\r67\r", 5, 8)) {
554
+ assertEquals(3, in.read(buffer));
555
+ assertEquals('6', buffer[0]);
556
+ assertEquals('7', buffer[1]);
557
+ assertEquals('\r', buffer[2]);
558
+ }
559
+ }
560
+
561
+ private InputStream createInput(String s, int start, int end)
562
+ {
563
+ try {
564
+ return new PartialFileInputStream(new ByteArrayInputStream(s.getBytes("UTF-8")), start, end);
565
+ } catch (UnsupportedEncodingException e) {
566
+ throw new RuntimeException(e);
567
+ }
568
+ }
569
+
570
+ }