当前位置: 首页>>代码示例>>Java>>正文


Java RecoverableIOException类代码示例

本文整理汇总了Java中org.archive.io.RecoverableIOException的典型用法代码示例。如果您正苦于以下问题:Java RecoverableIOException类的具体用法?Java RecoverableIOException怎么用?Java RecoverableIOException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RecoverableIOException类属于org.archive.io包,在下文中一共展示了RecoverableIOException类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createArchiveRecord

import org.archive.io.RecoverableIOException; //导入依赖的package包/类
/**
 * Create new arc record.
 *
 * Encapsulate housekeeping that has to do w/ creating a new record.
 *
 * <p>Call this method at end of constructor to read in the
 * arcfile header.  Will be problems reading subsequent arc records
 * if you don't since arcfile header has the list of metadata fields for
 * all records that follow.
 * 
 * <p>When parsing through ARCs writing out CDX info, we spend about
 * 38% of CPU in here -- about 30% of which is in getTokenizedHeaderLine
 * -- of which 16% is reading.
 *
 * @param is InputStream to use.
 * @param offset Absolute offset into arc file.
 * @return An arc record.
 * @throws IOException
 */
protected ARCRecord createArchiveRecord(InputStream is, long offset)
throws IOException {
    try {
        String version = super.getVersion();
        ARCRecord record = new ARCRecord(is, getReaderIdentifier(), offset,
                isDigest(), isStrict(), isParseHttpHeaders(),
                isAlignedOnFirstRecord(), version);
        if (version != null && super.getVersion() == null)
            super.setVersion(version);
        currentRecord(record);
    } catch (IOException e) {
        if (e instanceof RecoverableIOException) {
            // Don't mess with RecoverableIOExceptions.  Let them out.
            throw e;
        }
        IOException newE = new IOException(e.getMessage() + " (Offset " +
                offset + ").");
        newE.setStackTrace(e.getStackTrace());
        throw newE;
    }
    return (ARCRecord)getCurrentRecord();
}
 
开发者ID:iipc,项目名称:webarchive-commons,代码行数:42,代码来源:ARCReader.java

示例2: adaptWARCHTTPResponse

import org.archive.io.RecoverableIOException; //导入依赖的package包/类
private CaptureSearchResult adaptWARCHTTPResponse(CaptureSearchResult result,
		WARCRecord rec) throws IOException {

	ArchiveRecordHeader header = rec.getHeader();
	// need to parse the documents HTTP message and headers here: WARCReader
	// does not implement this... yet..
	
       byte [] statusBytes = HttpParser.readRawLine(rec);
       int eolCharCount = getEolCharsCount(statusBytes);
       if (eolCharCount <= 0) {
           throw new RecoverableIOException("Failed to read http status where one " +
                   " was expected: " + 
                   ((statusBytes == null) ? "(null)" : new String(statusBytes)));
       }
       String statusLine = EncodingUtil.getString(statusBytes, 0,
           statusBytes.length - eolCharCount, ARCConstants.DEFAULT_ENCODING);
       if ((statusLine == null) ||
               !StatusLine.startsWithHTTP(statusLine)) {
          throw new RecoverableIOException("Failed parse of http status line.");
       }
       StatusLine status = new StatusLine(statusLine);
	result.setHttpCode(String.valueOf(status.getStatusCode()));
       
	Header[] headers = HttpParser.parseHeaders(rec,
               ARCConstants.DEFAULT_ENCODING);

	
	annotater.annotateHTTPContent(result,rec,headers,header.getMimetype());

	return result;
}
 
开发者ID:netarchivesuite,项目名称:netarchivesuite-svngit-migration,代码行数:32,代码来源:NetarchiveSuiteWARCRecordToSearchResultAdapter.java

示例3: getTokenizedHeaderLine

import org.archive.io.RecoverableIOException; //导入依赖的package包/类
/**
 * Get a record header line as list of tokens.
 *
 * We keep reading till we find a LINE_SEPARATOR or we reach the end
 * of file w/o finding a LINE_SEPARATOR or the line length is crazy.
 *
 * @param stream InputStream to read from.
 * @param list Empty list that gets filled w/ string tokens.
 * @return Count of characters read.
 * @exception IOException If problem reading stream or no line separator
 * found or EOF before EOL or we didn't get minimum header fields.
 */
private int getTokenizedHeaderLine(final InputStream stream,
        List<String> list) throws IOException {
    // Preallocate usual line size.
    StringBuilder buffer = new StringBuilder(2048 + 20);
    int read = 0;
    int previous = -1;
    for (int c = -1; true;) {
            previous = c;
        c = stream.read();
        if (c == -1) {
            throw new RecoverableIOException("Hit EOF before header EOL.");
        }
        c &= 0xff; 
        read++;
        if (read > MAX_HEADER_LINE_LENGTH) {
            throw new IOException("Header line longer than max allowed " +
                " -- " + String.valueOf(MAX_HEADER_LINE_LENGTH) +
                " -- or passed buffer doesn't contain a line (Read: " +
                buffer.length() + ").  Here's" +
                " some of what was read: " +
                buffer.substring(0, Math.min(buffer.length(), 256)));
        }

        if (c == LINE_SEPARATOR) {
            if (buffer.length() == 0) {
                // Empty line at start of buffer.  Skip it and try again.
                continue;
            }

            if (list != null) {
                list.add(buffer.toString());
            }
            // LOOP TERMINATION.
            break;
        } else if (c == HEADER_FIELD_SEPARATOR) {
            if (!isStrict() && previous == HEADER_FIELD_SEPARATOR) {
                    // Early ARCs sometimes had multiple spaces between fields.
                    continue;
            }
            if (list != null) {
                list.add(buffer.toString());
            }
            // reset to empty
            buffer.setLength(0);
        } else {
            buffer.append((char)c);
        }
    }

    // List must have at least 3 elements in it and no more than 10.  If
    // it has other than this, then bogus parse.
    if (list != null && (list.size() < 3 || list.size() > 100)) {
        throw new IOException("Unparseable header line: " + list);
    }

    // save verbatim header String
    this.headerString = StringUtils.join(list," ");
    
    return read;
}
 
开发者ID:iipc,项目名称:webarchive-commons,代码行数:73,代码来源:ARCRecord.java


注:本文中的org.archive.io.RecoverableIOException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。