Java Code Examples for it.unimi.dsi.fastutil.io.FastBufferedInputStream#close()
The following examples show how to use
it.unimi.dsi.fastutil.io.FastBufferedInputStream#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GZIPArchiveReaderTest.java From BUbiNG with Apache License 2.0 | 6 votes |
@Test public void reverseGetEntry() throws IOException { final LongBigArrayBigList pos = GZIPIndexer.index(new FileInputStream(ARCHIVE_PATH)); GZIPArchive.ReadEntry re; FastBufferedInputStream fis = new FastBufferedInputStream(new FileInputStream(ARCHIVE_PATH)); GZIPArchiveReader gzar = new GZIPArchiveReader(fis); byte[] actualMagic = new byte[EXPECTED_MAGIC.length]; for (int i = (int) pos.size64() - 1; i >= 0; i--) { gzar.position(pos.getLong(i)); re = gzar.getEntry(); if (re == null) break; LazyInflater lin = re.lazyInflater; InputStream in = lin.get(); in.read(actualMagic); assertArrayEquals(EXPECTED_MAGIC, actualMagic); for (int j = 0; j < (i + 1) * 512; j++) in.read(); lin.consume(); } fis.close(); }
Example 2
Source File: ParallelBufferedWarcWriterTest.java From BUbiNG with Apache License 2.0 | 4 votes |
@Test public void testRecord() throws IOException, InterruptedException, URISyntaxException { for(boolean gzip: new boolean[] { true, false }) { final FastByteArrayOutputStream out = new FastByteArrayOutputStream(); final ParallelBufferedWarcWriter warcParallelOutputStream = new ParallelBufferedWarcWriter(out, gzip); final Thread thread[] = new Thread[NUM_THREADS]; final URI fakeUri = new URI("http://this.is/a/fake"); final RandomTestMocks.HttpResponse[] response = new RandomTestMocks.HttpResponse[NUM_RECORDS]; for(int i = 0; i < NUM_THREADS; i++) (thread[i] = new Thread(Integer.toString(i)) { @Override public void run() { final int index = Integer.parseInt(getName()); for (int i = index * (NUM_RECORDS / NUM_THREADS); i < (index + 1) * (NUM_RECORDS / NUM_THREADS); i++) { try { response[i] = new RandomTestMocks.HttpResponse(MAX_NUMBER_OF_HEADERS, MAX_LENGTH_OF_HEADER, MAX_LENGTH_OF_BODY, i); HttpResponseWarcRecord record = new HttpResponseWarcRecord(fakeUri, response[i]); warcParallelOutputStream.write(record); LOGGER.info("Thread " + index + " wrote record " + i); } catch(Exception e) { throw new RuntimeException(e); } } } }).start(); for(Thread t: thread) t.join(); warcParallelOutputStream.close(); out.close(); final FastBufferedInputStream in = new FastBufferedInputStream(new FastByteArrayInputStream(out.array, 0, out.length)); WarcReader reader = gzip ? new CompressedWarcReader(in) : new UncompressedWarcReader(in); final boolean found[] = new boolean[NUM_RECORDS]; for (int i = 0; i < NUM_RECORDS; i++) { final HttpResponseWarcRecord r = (HttpResponseWarcRecord) reader.read(); final int pos = Integer.parseInt(r.getFirstHeader("Position").getValue()); found[pos] = true; assertArrayEquals(ByteStreams.toByteArray(response[pos].getEntity().getContent()), ByteStreams.toByteArray(r.getEntity().getContent())); } in.close(); for(int i = NUM_RECORDS; i-- != 0;) assertTrue(Integer.toString(i), found[i]); } }