Find generation stamp from block file and meta file.
@param blockFile
@param metaFile
@return
@throws IOException
778040
static long parseGenerationStampInMetaFile(File blockFile, File metaFile
      ) throws IOException {
    String metaname = metaFile.getName();
    String gs = metaname.substring(blockFile.getName().length() + 1,
        metaname.length() - FSDataset.METADATA_EXTENSION.length());
    try {
      return Long.parseLong(gs);
    } catch(NumberFormatException nfe) {
      throw (IOException)new IOException("blockFile=" + blockFile
          + ", metaFile=" + metaFile).initCause(nfe);
    }
  }
214724
public static BlockReader newBlockReader( int dataTransferVersion,
                                     int namespaceId,
                                     Socket sock, String file, long blockId,
                                     long genStamp,
                                     long startOffset, long len,
                                     int bufferSize, boolean verifyChecksum)
                                     throws IOException {
    return newBlockReader(dataTransferVersion, namespaceId,
                          sock, file, blockId, genStamp,
                          startOffset,
                          len, bufferSize, verifyChecksum, "",
                          Long.MAX_VALUE, -1, false, null,
                          new ReadOptions());
  }
397945
ActiveFile getOngoingCreates(int namespaceId, Block block) {
    checkBlock(block);
    NamespaceMap nm = getNamespaceMap(namespaceId);
    if (nm == null) {
      return null;
    }
    return nm.getOngoingCreates(block);
  }
1079987
public void checkSrcFile(FileSystem srcFs, FileStatus srcFile) 
  		throws IOException {
  	List<BlockInfo> srcBlocks = getBlockInfos(srcFs, srcFile);
  	if (srcBlocks.size() == 0) {
  		return;
  	}
  	
  	BlockAndDatanodeResolver resolver = new BlockAndDatanodeResolver(srcFile.getPath(), srcFs);
  	checkSrcBlockLocations(srcBlocks, srcFile, resolver);
  }
1035059
public BlockMeta getBlockMeta(long blockId) throws BlockDoesNotExistException {
    BlockMeta blockMeta = mBlockIdToBlockMap.get(blockId);
    if (blockMeta == null) {
      throw new BlockDoesNotExistException(ExceptionMessage.BLOCK_META_NOT_FOUND, blockId);
    }
    return blockMeta;
  }
988373
private boolean generateJavaCode(File baseFile, File dataFile, File extendedFile) {
        return (baseFile.lastModified() < dataFile.lastModified() || (extendedFile.exists() && baseFile.lastModified() < extendedFile
            .lastModified()));
    }
31781
public static BlockInfoEx newInstance(File file) {
        BlockInfoEx blockInfo = new BlockInfoEx();
        blockInfo.logFile = file;

        BufferedReader reader = null;
        try {
            InputStreamReader in = new InputStreamReader(new FileInputStream(file), "UTF-8");

            reader = new BufferedReader(in);
            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                if (line.startsWith(KEY_QUA)) {
                    blockInfo.qualifier = line.split(KV)[1];
                } else if (line.startsWith(KEY_MODEL)) {
                    blockInfo.model = line.split(KV)[1];
                } else if (line.startsWith(KEY_API)) {
                    blockInfo.apiLevel = line.split(KV)[1];
                } else if (line.startsWith(KEY_IMEI)) {
                    blockInfo.imei = line.split(KV)[1];
                } else if (line.startsWith(KEY_CPU_CORE)) {
                    blockInfo.cpuCoreNum = Integer.valueOf(line.split(KV)[1]);
                } else if (line.startsWith(KEY_UID)) {
                    blockInfo.uid = line.split(KV)[1];
                } else if (line.startsWith(KEY_TIME_COST_START)) {
                    blockInfo.timeStart = line.split(KV)[1];
                } else if (line.startsWith(KEY_TIME_COST_END)) {
                    blockInfo.timeEnd = line.split(KV)[1];
                } else if (line.startsWith(KEY_TIME_COST)) {
                    blockInfo.timeCost = Long.valueOf(line.split(KV)[1]);
                } else if (line.startsWith(KEY_THREAD_TIME_COST)) {
                    blockInfo.threadTimeCost = Long.valueOf(line.split(KV)[1]);
                } else if (line.startsWith(KEY_PROCESS)) {
                    blockInfo.processName = line.split(KV)[1];
                } else if (line.startsWith(KEY_VERSION_NAME)) {
                    blockInfo.versionName = line.split(KV)[1];
                } else if (line.startsWith(KEY_VERSION_CODE)) {
                    blockInfo.versionCode = Integer.valueOf(line.split(KV)[1]);
                } else if (line.startsWith(KEY_NETWORK)) {
                    blockInfo.network = line.split(KV)[1];
                } else if (line.startsWith(KEY_TOTAL_MEMORY)) {
                    blockInfo.totalMemory = line.split(KV)[1];
                } else if (line.startsWith(KEY_FREE_MEMORY)) {
                    blockInfo.freeMemory = line.split(KV)[1];
                } else if (line.startsWith(KEY_CPU_BUSY)) {
                    blockInfo.cpuBusy = Boolean.valueOf(line.split(KV)[1]);
                } else if (line.startsWith(KEY_CPU_RATE)) {
                    String[] split = line.split(KV);
                    if (split.length > 1) {
                        StringBuilder cpuRateSb = new StringBuilder(split[1]);
                        cpuRateSb.append(line.split(KV)[1]).append(SEPARATOR);
                        line = reader.readLine();

                        // read until SEPARATOR appears
                        while (line != null) {
                            if (!line.equals("")) {
                                cpuRateSb.append(line).append(SEPARATOR);
                            } else {
                                break;
                            }
                            line = reader.readLine();
                        }
                        blockInfo.cpuRateInfo = cpuRateSb.toString();
                    }
                } else if (line.startsWith(KEY_STACK)) {
                    StringBuilder stackSb = new StringBuilder(line.split(KV)[1]);
                    line = reader.readLine();

                    // read until file ends
                    while (line != null) {
                        if (!line.equals("")) {
                            stackSb.append(line).append(SEPARATOR);
                        } else if (stackSb.length() > 0) {
                            // ignore continual blank lines
                            blockInfo.threadStackEntries.add(stackSb.toString());
                            stackSb = new StringBuilder();
                        }
                        line = reader.readLine();
                    }
                }
            }
            reader.close();
            reader = null;
        } catch (Throwable t) {
            Log.e(TAG, NEW_INSTANCE_METHOD, t);
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (Exception e) {
                Log.e(TAG, NEW_INSTANCE_METHOD, e);
            }
        }
        blockInfo.flushString();
        return blockInfo;
    }
618072
@Override
    public File getFullFile(String pRelativePath) throws TTIOException, IOException {
        MetaValue value = (MetaValue)mPageReadTrx.getMetaBucket().get(new MetaKey(pRelativePath));

        File file =
            new File(new StringBuilder().append(mTmpDir.getAbsolutePath()).append(File.separator).append(
                pRelativePath).toString());

        if (file.exists()) {
            file.delete();
        }

        file.createNewFile();

        if (value.getData() == emptyFileKey) {
            return file;
        }

        FileData node = (FileData)mPageReadTrx.getData(value.getData());

        OutputSupplier<FileOutputStream> supplier = Files.newOutputStreamSupplier(file, true);

        // Iterating as long as we didn't find the end of the file
        // and writing the bytes to a temporary file.
        do {
            supplier.getOutput().write(node.getVal());
            node = (FileData)mPageReadTrx.getData(node.getDataKey() + 1);
        } while (!node.isEof());

        supplier.getOutput().close();

        return file;
    }
1358357
Block addBlock(String path, INode[] inodes, Block block) throws IOException {
    waitForReady();

    writeLock();
    try {
      INodeFile fileNode = (INodeFile) inodes[inodes.length-1];
      INode.enforceRegularStorageINode(fileNode, 
          "addBlock only works for regular file, not " + path);
      
      // check quota limits and updated space consumed
      updateCount(inodes, inodes.length-1, 0,
          fileNode.getPreferredBlockSize()*fileNode.getReplication(), true);

      // associate the new list of blocks with this file
      BlockInfo blockInfo = 
          getFSNamesystem().blocksMap.addINode(block, fileNode,
              fileNode.getReplication());
      fileNode.getStorage().addBlock(blockInfo);

      if (NameNode.stateChangeLog.isDebugEnabled()) {
        NameNode.stateChangeLog.debug("DIR* FSDirectory.addFile: "
                                      + path + " with " + block
                                      + " block is added to the in-memory "
                                      + "file system");
      }
    } finally {
      writeUnlock();
    }
    return block;
  }
774137
static public int getBlockCrc(DataNode datanode, ReplicaToRead ri,
      int namespaceId, Block block) throws IOException {
    InputStream rawStreamIn = null;
    DataInputStream streamIn = null;
    try {
      int bytesPerCRC;
      int checksumSize;

      long crcPerBlock;

      rawStreamIn = BlockWithChecksumFileReader.getMetaDataInputStream(
          datanode.data, namespaceId, block);
      streamIn = new DataInputStream(new BufferedInputStream(rawStreamIn,
          FSConstants.BUFFER_SIZE));

      final BlockMetadataHeader header = BlockMetadataHeader
          .readHeader(streamIn);
      final DataChecksum checksum = header.getChecksum();
      if (checksum.getChecksumType() != DataChecksum.CHECKSUM_CRC32) {
        throw new IOException("File Checksum now is only supported for CRC32");
      }

      bytesPerCRC = checksum.getBytesPerChecksum();
      checksumSize = checksum.getChecksumSize();
      crcPerBlock = (((BlockWithChecksumFileReader.MetaDataInputStream) rawStreamIn)
          .getLength() - BlockMetadataHeader.getHeaderSize()) / checksumSize;

      int blockCrc = 0;
      byte[] buffer = new byte[checksumSize];
      for (int i = 0; i < crcPerBlock; i++) {
        IOUtils.readFully(streamIn, buffer, 0, buffer.length);
        int intChecksum = ((buffer[0] & 0xff) << 24)
            | ((buffer[1] & 0xff) << 16) | ((buffer[2] & 0xff) << 8)
            | ((buffer[3] & 0xff));

        if (i == 0) {
          blockCrc = intChecksum;
        } else {
          int chunkLength;
          if (i != crcPerBlock - 1 || ri.getBytesVisible() % bytesPerCRC == 0) {
            chunkLength = bytesPerCRC;
          } else {
            chunkLength = (int) ri.getBytesVisible() % bytesPerCRC;
          }
          blockCrc = CrcConcat.concatCrc(blockCrc, intChecksum, chunkLength);
        }
      }
      return blockCrc;
    } finally {
      if (streamIn != null) {
        IOUtils.closeStream(streamIn);
      }
      if (rawStreamIn != null) {
        IOUtils.closeStream(rawStreamIn);
      }
    }
  }
520095
public static BlockMetadataHeader readHeader(DataInputStream in,
                                Checksum checksumImpl) throws IOException {
    return readHeader(in.readShort(), in, checksumImpl);
  }
225806
int getBlockIndex(INodeFile inode, Block blk, String file) throws IOException {
    if (inode == null) {
      throw new IOException("inode for file " + file + " is null");
    }
    readLock();
    try {
      return inode.getBlockIndex(blk, file);
    } finally {
      readUnlock();
    }
  }
1362160
File validateBlockFile(int namespaceId, Block b) throws IOException {
    return getValidateBlockFile(namespaceId, b, false);
  }
1076050
private void replicateLastBlock(String src, INodeFileUnderConstruction file) {
    BlockInfo[] blks = file.getBlocks();
    if (blks == null || blks.length == 0)
      return;
    BlockInfo block = blks[blks.length-1];
    DatanodeDescriptor[] targets = file.getValidTargets();
    final int numOfTargets = targets == null ? 0 : targets.length;
    NumberReplicas status = countNodes(block);
    int totalReplicas = status.getTotal();
    if (numOfTargets > totalReplicas) {
      pendingReplications.add(block, numOfTargets-totalReplicas);
    }
    int expectedReplicas = file.getReplication();
    if (numOfTargets < expectedReplicas || 
        status.decommissionedReplicas != 0 ||
        status.corruptReplicas != 0) {
      LOG.info("Add " + block + " of " + src + " to needReplication queue: " + 
          " numOfTargets = " + numOfTargets +
          " decomissionedReplicas = " + status.decommissionedReplicas +
          " corruptReplicas = " + status.corruptReplicas);
      neededReplications.add(block, status.liveReplicas, 
          status.decommissionedReplicas, expectedReplicas);
    }
    
    // update metrics
    if (numOfTargets < expectedReplicas) {
      if (numOfTargets == 1) {
        myFSMetrics.numNewBlocksWithOneReplica.inc();
      }
    } else {
      myFSMetrics.numNewBlocksWithoutFailure.inc();
    }
    myFSMetrics.numNewBlocks.inc();
  }
1131787
private File getTargetFile(File sourceFile, OutputFormat selectedOutputFormat) throws IOException {

    File sourceDirectory = getSourceDirectory();
    String relativePath = StringUtils.substringAfter(sourceFile.getAbsolutePath(), sourceDirectory.getAbsolutePath());
    String relativeTargetPath = FileUtils.removeExtension(relativePath) + "." + selectedOutputFormat.getFileExtension();

    File jsonFile = new File(getGeneratedResourcesFolder().getPath() + relativeTargetPath);

    jsonFile = jsonFile.getCanonicalFile();

    File parentDirectory = jsonFile.getParentFile();
    if (!parentDirectory.exists()) {
      parentDirectory.mkdirs();
      buildContext.refresh(parentDirectory);
    }

    return jsonFile;
  }
518569
def read_block_idb(self, block, _):
        """"""
        options = block[16:]
        tsresol = 1000000
        while len(options) >= 4:
            code, length = struct.unpack(self.endian + "HH", options[:4])
            # PCAP Next Generation (pcapng) Capture File Format
            # 4.2. - 
            # http://xml2rfc.tools.ietf.org/cgi-bin/xml2rfc.cgi?url=https://raw.githubusercontent.com/pcapng/pcapng/master/draft-tuexen-opsawg-pcapng.xml&modeAsFormat=html/ascii&type=ascii#rfc.section.4.2
            if code == 9 and length == 1 and len(options) >= 5:
                tsresol = orb(options[4])
                tsresol = (2 if tsresol & 128 else 10) ** (tsresol & 127)
            if code == 0:
                if length != 0:
                    warning("PcapNg: invalid option length %d for end-of-option" % length)  # noqa: E501
                break
            if length % 4:
                length += (4 - (length % 4))
            options = options[4 + length:]
        self.interfaces.append(struct.unpack(self.endian + "HxxI", block[:8]) +
                               (tsresol,))
171535
public File getBlockFile(int namespaceId, Block b) throws IOException {
    File f = validateBlockFile(namespaceId, b);
    if (f == null) {
      if (InterDatanodeProtocol.LOG.isDebugEnabled()) {
        InterDatanodeProtocol.LOG
            .debug("b=" + b + ", volumeMap=" + volumeMap);
      }
      throw new IOException("Block " + b + ", namespace= " + namespaceId
          + " is not valid.");
    }
    return f;
  }