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


Java FSOutputSummer类代码示例

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


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

示例1: writePacket

import org.apache.hadoop.fs.FSOutputSummer; //导入依赖的package包/类
@Override
void writePacket(DataTransferPacket packet) throws IOException {
	
	if (!writtenHeader) {
		writeChecksumHeader(checksum);
		writtenHeader = true;
	}
	
    boolean forceSync = packet.isForceSync();
    int dataLength = packet.dataLength;
    
    if (dataLength <= 0) {
      LOG.warn("NTar: writePacket: Receiving empty packet:" + 
    		  packet + " for block " + block);
    } else {
      dataLength = (int) Math.min(dataLength, this.length - this.writtenLength);
      setBlockPosition(offsetInBlock);  // adjust file position
      offsetInBlock += dataLength;
      this.writtenLength += dataLength;

      int checksumLength = (dataLength + bytesPerChecksum -1)/bytesPerChecksum 
    		  * checksumSize;
     
      byte[] pktBuf = new byte[checksumLength + dataLength];
      Arrays.fill(pktBuf, (byte)0);
      System.arraycopy(packet.buffer, 0, pktBuf, 
    		  checksumLength, dataLength);
      ChecksumUtil.updateChunkChecksum(pktBuf, 0,
    		  checksumLength, dataLength, checksum);
      
      try {
        if (!finalized) {
          long writeStartTime = System.currentTimeMillis();
          //finally write to the disk :
          out.write(pktBuf, checksumLength, dataLength);

          // If this is a partial chunk, then verify that this is the only
          // chunk in the packet. Calculate new crc for this chunk.
          if (partialCrc != null) {
            if (dataLength > bytesPerChecksum) {
              throw new IOException("Got wrong length during mergeBlock(" + 
                                    block + ") from " + childAddrs + " " +
                                    "A packet can have only one partial chunk."+
                                    " len = " + dataLength + 
                                    " bytesPerChecksum " + bytesPerChecksum);
            }
            partialCrc.update(pktBuf, checksumLength, dataLength);
            byte[] buf = FSOutputSummer.convertToByteStream(partialCrc, checksumSize);
            checksumOut.write(buf);
            LOG.debug("Writing out partial crc for data len " + dataLength);
            partialCrc = null;
          } else {
            checksumOut.write(pktBuf, 0, checksumLength);
          }
          datanode.myMetrics.bytesWritten.inc(dataLength);

          flush(forceSync);

          this.replicaBeingWritten.setBytesOnDisk(offsetInBlock);
          // Record time taken to write packet
          long writePacketDuration = System.currentTimeMillis() - writeStartTime;
          datanode.myMetrics.writePacketLatency.inc(writePacketDuration);
        }
      } catch (ClosedByInterruptException cix) {
        LOG.warn( "NTar: Thread interrupted when flushing bytes to disk."
        		+ "Might cause inconsistent sates", cix);
        throw cix;
      } catch (InterruptedIOException iix) {
        LOG.warn(
            "NTar: InterruptedIOException when flushing bytes to disk."
        		+ "Might cause inconsistent sates", iix);
        throw iix;
      } catch (IOException iex) {
        datanode.checkDiskError(iex);
        throw iex;
      }
    }
  }
 
开发者ID:iVCE,项目名称:RDFS,代码行数:79,代码来源:BlockXCodingMerger.java


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