Package org.archive.io

Examples of org.archive.io.WriterPoolMember


        }
    }
   
    protected ARCReader getSingleRecordReader(String name) throws Exception {
        // Get an ARC with one record.
        WriterPoolMember w = createArcWithOneRecord(name, true);
        w.close();
        // Get reader on said ARC.
        ARCReader r = ARCReaderFactory.get(w.getFile());
        return r;
    }
View Full Code Here


            assertEquals("Number active", i + 1, pool.getNumActive());
            ((ARCWriter)writers[i]).write("http://one.two.three", "no-type",
              "0.0.0.0", 1234567890, CONTENT.length(), baos);
        }
    
        WriterPoolMember writer2Invalidate = writers[pool.getNumActive() - 1];
        writers[pool.getNumActive() - 1] = null;
        pool.invalidateFile(writer2Invalidate);
        for (int i = 0; i < (MAX_ACTIVE - 1); i++) {
            if (writers[i] == null) {
                continue;
View Full Code Here

    }
   
    protected ProcessResult write(CrawlURI curi, long recordLength,
            InputStream in, String ip)
    throws IOException {
        WriterPoolMember writer = getPool().borrowFile();
        long position = writer.getPosition();
        // See if we need to open a new file because we've exceeded maxBytes.
        // Call to checkFileSize will open new file if we're at maximum for
        // current file.
        writer.checkSize();
        if (writer.getPosition() != position) {
            // We just closed the file because it was larger than maxBytes.
            // Add to the totalBytesWritten the size of the first record
            // in the file, if any.
            setTotalBytesWritten(getTotalBytesWritten() +
              (writer.getPosition() - position));
            position = writer.getPosition();
        }
       
        ARCWriter w = (ARCWriter)writer;
        try {
            if (in instanceof ReplayInputStream) {
                w.write(curi.toString(), curi.getContentType(),
                    ip, curi.getFetchBeginTime(),
                    recordLength, (ReplayInputStream)in);
            } else {
                w.write(curi.toString(), curi.getContentType(),
                    ip, curi.getFetchBeginTime(),
                    recordLength, in);
            }
        } catch (IOException e) {
            // Invalidate this file (It gets a '.invalid' suffix).
            getPool().invalidateFile(writer);
            // Set the writer to null otherwise the pool accounting
            // of how many active writers gets skewed if we subsequently
            // do a returnWriter call on this object in the finally block.
            writer = null;
            throw e;
        } finally {
            if (writer != null) {
              setTotalBytesWritten(getTotalBytesWritten() +
                   (writer.getPosition() - position));
                getPool().returnFile(writer);
               
                String filename = writer.getFile().getName();
                if (filename.endsWith(ArchiveFileConstants.OCCUPIED_SUFFIX)) {
                    filename = filename.substring(0, filename.length() - ArchiveFileConstants.OCCUPIED_SUFFIX.length());
                }
                curi.addExtraInfo("arcFilename", filename);
               
View Full Code Here

//        logger.info("Finished speed write test.");
//    }
   
    public void testArcRecordOffsetReads() throws Exception {
      // Get an ARC with one record.
    WriterPoolMember w =
      createWithOneRecord("testArcRecordInBufferStream", true);
    w.close();
    // Get reader on said ARC.
    WARCReader r = WARCReaderFactory.get(w.getFile());
    final Iterator<ArchiveRecord> i = r.iterator();
    // Skip first ARC meta record.
    ArchiveRecord ar = i.next();
    i.hasNext();
    // Now we're at first and only record in ARC.
View Full Code Here

TOP

Related Classes of org.archive.io.WriterPoolMember

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.