Java Code Examples for java.io.DataInputStream#readBoolean()

The following examples show how to use java.io.DataInputStream#readBoolean() . 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: StateMapSerDe.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public StateMapUpdate deserializeRecord(final DataInputStream in, final int version) throws IOException {
    final String componentId = in.readUTF();
    final String updateTypeName = in.readUTF();
    final UpdateType updateType = UpdateType.valueOf(updateTypeName);
    if (updateType == UpdateType.DELETE) {
        return new StateMapUpdate(null, componentId, updateType);
    }

    final long recordVersion = in.readLong();
    final int numEntries = in.readInt();
    final Map<String, String> stateValues = new HashMap<>(numEntries);
    for (int i = 0; i < numEntries; i++) {
        final boolean hasKey = in.readBoolean();
        final String key = hasKey ? in.readUTF() : null;
        final boolean hasValue = in.readBoolean();
        final String value = hasValue ? in.readUTF() : null;
        stateValues.put(key, value);
    }

    return new StateMapUpdate(new StandardStateMap(stateValues, recordVersion), componentId, updateType);
}
 
Example 2
Source File: GeometryRTree.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void read(DataInputStream stream) throws IOException {
    mLeaf = stream.readBoolean();
    double minX = stream.readDouble();
    double minY = stream.readDouble();
    double maxX = stream.readDouble();
    double maxY = stream.readDouble();
    mCoords.setMin(minX, minY);
    mCoords.setMax(maxX, maxY);
    int size = stream.readInt();
    for(int i = 0; i < size; i++){
        if(stream.readBoolean()){
            Node childNode = new Node();
            childNode.read(stream);
            add(childNode);
        }
        else {
            Entry childEntry = new Entry();
            childEntry.read(stream);
            add(childEntry);
        }
    }
}
 
Example 3
Source File: CCQuantifierDataManager.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
public IQuantifier read(IStorageManager storageManager, String modelName) {
    IClassifier classifier = classifierDataManager.read(storageManager,
            modelName + classifierSuffix);
    IClassifierRuntimeCustomizer customizer = classifierDataManager
            .readClassifierRuntimeConfiguration(storageManager, modelName
                    + classifierSuffix);
    DataInputStream reader = new DataInputStream(
            storageManager.getInputStreamForResource(modelName
                    + thresholdSuffix));
    try {
        boolean perDocument = reader.readBoolean();
        ClassificationMode classificationMode = ClassificationMode.PER_DOCUMENT;
        if (perDocument) {
            classificationMode = ClassificationMode.PER_DOCUMENT;
        } else {
            classificationMode = ClassificationMode.PER_DOCUMENT;
        }
        boolean hasThresholds = reader.readBoolean();
        if (hasThresholds) {
            TShortDoubleHashMap thresholds = new TShortDoubleHashMap();
            int count = reader.readInt();
            for (int i = 0; i < count; ++i) {
                short cat = reader.readShort();
                double value = reader.readDouble();
                thresholds.put(cat, value);
            }
            reader.close();
            return new CCQuantifier(classifier, customizer,
                    classificationMode, thresholds);
        } else {
            reader.close();
            return new CCQuantifier(classifier, customizer,
                    classificationMode);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source File: SerializerUtils.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static List<Integer> readIntegerList(final DataInputStream in) throws IOException {

      if (in.readBoolean()) {

         return null;
      } else {
         final int size = in.readInt();
         final List<Integer> result = new ArrayList<Integer>(size);
         for (int i = 0; i < size; i++) {

            result.add(IntegerUtils.valueOf(in.readInt()));
         }
         return result;
      }
   }
 
Example 5
Source File: HprofHeap.java    From netbeans with Apache License 2.0 5 votes vote down vote up
HprofHeap(DataInputStream dis, CacheDirectory cacheDir) throws IOException {
    String id = dis.readUTF();
    if (!SNAPSHOT_ID.equals(id)) {
        throw new IOException("Invalid HPROF dump id "+id);
    }
    int version = dis.readInt();
    if (version != SNAPSHOT_VERSION) {
        throw new IOException("Invalid HPROF version "+SNAPSHOT_VERSION+" loaded "+version);            
    }
    heapDumpFile = cacheDir.getHeapFile(dis.readUTF());
    cacheDirectory = cacheDir;
    dumpBuffer = HprofByteBuffer.createHprofByteBuffer(heapDumpFile);
    nearestGCRoot = new NearestGCRoot(this, dis);
    allInstanceDumpBounds = new TagBounds(dis);
    heapDumpSegment = new TagBounds(dis);
    heapTagBounds = new TagBounds[0x100];
    TagBounds.readFromStream(dis, this, heapTagBounds);
    TagBounds.readFromStream(dis, this, tagBounds);        
    instancesCountComputed = dis.readBoolean();
    referencesComputed = dis.readBoolean();
    retainedSizeComputed = dis.readBoolean();
    retainedSizeByClassComputed = dis.readBoolean();
    idMapSize = dis.readInt();
    segment = dis.readInt();
    idToOffsetMap = new LongMap(dis, cacheDirectory);
    if (dis.readBoolean()) {
        domTree = new DominatorTree(this, dis);
    }
    gcRoots = new HprofGCRoots(this);
    getClassDumpSegment().extractSpecialClasses();            
}
 
Example 6
Source File: TimeRequest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static TimeRequest fromByteArray(byte[] bytes) throws IOException
{
  ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
  DataInputStream dataIn = new DataInputStream(bi);
  byte packetId = dataIn.readByte();
  boolean isNanoTime = dataIn.readBoolean();
  return new TimeRequest(packetId, isNanoTime);

}
 
Example 7
Source File: Message.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void readWire(final DataInputStream in) throws IOException, ClassNotFoundException {

      type = in.readInt();
      requiresSameCluster = in.readBoolean();
      timestamp = SerializerUtils.readTime(in);
      clusterUUID = SerializerUtils.readUuid(in);
      sender = SerializerUtils.readAddress(in);
      receiver = SerializerUtils.readReceiverAddress(in);
   }
 
Example 8
Source File: IonoGalileo.java    From GNSS_Compare with Apache License 2.0 5 votes vote down vote up
@Override
public void read(DataInputStream dai, boolean oldVersion) throws IOException {
	int v=1;
	if(!oldVersion) v=dai.readInt();

	if(v==1){

		health = dai.readLong();
		utcA1 = dai.readDouble();
		utcA0 = dai.readDouble();
		utcTOW = dai.readLong();
		utcWNT = dai.readInt();
		utcLS = dai.readInt();
		utcWNF = dai.readInt();
		utcDN = dai.readInt();
		utcLSF = dai.readInt();
		for(int i=0;i<alpha.length;i++){
			alpha[i] = dai.readFloat();
		}
		for(int i=0;i<beta.length;i++){
			beta[i] = dai.readFloat();
		}
		validHealth = dai.readBoolean();
		validUTC = dai.readBoolean();
		validKlobuchar = dai.readBoolean();
		long l = dai.readLong();
		refTime = new Time(l>0?l:System.currentTimeMillis());
	}else{
		throw new IOException("Unknown format version:"+v);
	}
}
 
Example 9
Source File: AggregatingRequest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void readWire(final DataInputStream in) throws IOException, ClassNotFoundException {

   super.readWire(in);

   prepared = in.readBoolean();
   storageNumber = SerializerUtils.readInteger(in);
}
 
Example 10
Source File: PutRequest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void readWire(final DataInputStream in) throws IOException, ClassNotFoundException {

   super.readWire(in);
   value = SerializerUtils.readBinary(in);
   expirationTime = SerializerUtils.readTime(in);
   putOnlyIfAbsent = in.readBoolean();
}
 
Example 11
Source File: RestrictionData.java    From brouter with MIT License 5 votes vote down vote up
public RestrictionData( DataInputStream di ) throws Exception
{
  isPositive = di.readBoolean();
  exceptions = di.readShort();
  fromWid = readId( di );
  toWid = readId( di );
  viaNid = readId( di );
}
 
Example 12
Source File: SegmentDownloadAction.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final DownloadAction readFromStream(int version, DataInputStream input)
    throws IOException {
  Uri uri = Uri.parse(input.readUTF());
  boolean isRemoveAction = input.readBoolean();
  int dataLength = input.readInt();
  byte[] data = new byte[dataLength];
  input.readFully(data);
  int keyCount = input.readInt();
  List<StreamKey> keys = new ArrayList<>();
  for (int i = 0; i < keyCount; i++) {
    keys.add(readKey(version, input));
  }
  return createDownloadAction(uri, isRemoveAction, data, keys);
}
 
Example 13
Source File: AvatarNode.java    From RDFS with Apache License 2.0 5 votes vote down vote up
private String verifyFailoverTestData() throws IOException {
  if (!enableTestFramework) {
    LOG.info("Failover: Test framework - disabled");
    return "";
  }
  String fsck = "";
  LOG.info("Failover: Test framework - verification - starting...");
  AvatarFailoverSnapshot snapshot = new AvatarFailoverSnapshot();
  File snapshotFile = getSnapshotFile(confg);
  DataInputStream in = new DataInputStream(
      new BufferedInputStream(new FileInputStream(snapshotFile)));
  try {
    snapshot.readFields(in);
    if (in.readBoolean()) {
      LOG.info("Failover: Test framework - found fsck data");
      fsck = Text.readString(in);
    }
  } finally {
    in.close();
  }
  
  LOG.info("Failover: Test framework - verifying open files: found " 
      + snapshot.getOpenFilesInfo().getOpenFiles().size() 
      + " files in the test snapshot");  
  verifyOpenFiles(snapshot.getOpenFilesInfo());
  
  LOG.info("Failover: Test framework - verifying closed files: found " 
      + snapshot.getSampledFiles().size() 
      + " files in the test snapshot");    
  for (FileStatusExtended stat : snapshot.getSampledFiles()) {
    verifySnapshotSampledFile(stat);
  }

  LOG.info("Failover: Test framework - verification - succeeded");
  return fsck;
}
 
Example 14
Source File: NativeChannel.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Measures the next data from channel.
 *
 * @param sensorNumber - number of sensor
 * @param channelNumber - number of channel
 * @param sensorType
 * @return error code of measuring
 */
protected synchronized int measureData(int sensorNumber, int channelNumber) {

  byte[] buffer = doMeasureData(sensorNumber,channelNumber);
  
  
  if (buffer.length < 0)
    return ValueListener.SENSOR_UNAVAILABLE;
    
  DataInputStream is =
            new DataInputStream(new ByteArrayInputStream(buffer));
  try {
    byte dataType = is.readByte();
    int dataLen = is.readInt();
  
    validityBuffers = new boolean[dataLen];
    uncertaintyBuffers = new float[dataLen];

    if (dataType == 1) {
      dataBuffers = new Double[dataLen];
    } else if (dataType == 2) {
      dataBuffers = new Integer[dataLen];
    } else if (dataType == 4) {
      dataBuffers = new Object[dataLen];
    } else {
      return ValueListener.MEASURING_FAIL;
    }
    for (int i = 0; i < dataLen; i++) {
      validityBuffers[i] = is.readBoolean();
      uncertaintyBuffers[i] = is.readFloat();
      if (dataType == 1) {
        dataBuffers[i] = new Double(is.readDouble());
      } else if (dataType == 2) {
        dataBuffers[i] = new Integer(is.readInt());
      } else if (dataType == 4) {
        // TODO use custom "object decoder" instance
        throw new RuntimeException("Unsupported data type object");
      }
    }
  } catch (IOException e) {
    return ValueListener.MEASURING_FAIL;
  }
  return ValueListener.DATA_READ_OK;
}
 
Example 15
Source File: ImageLoaderCurrent.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Process an INode
 * 
 * @param in image stream
 * @param v visitor
 * @param skipBlocks skip blocks or not
 * @param parentName the name of its parent node
 * @param isSnapshotCopy whether or not the inode is a snapshot copy
 * @throws IOException
 */
private void processINode(DataInputStream in, ImageVisitor v,
    boolean skipBlocks, String parentName, boolean isSnapshotCopy)
    throws IOException {
  boolean supportSnapshot = 
      NameNodeLayoutVersion.supports(Feature.SNAPSHOT, imageVersion);
  boolean supportInodeId = 
      NameNodeLayoutVersion.supports(Feature.ADD_INODE_ID, imageVersion);
  
  v.visitEnclosingElement(ImageElement.INODE);
  final String pathName = readINodePath(in, parentName);
  v.visit(ImageElement.INODE_PATH, pathName);

  long inodeId = INodeId.GRANDFATHER_INODE_ID;
  if (supportInodeId) {
    inodeId = in.readLong();
    v.visit(ImageElement.INODE_ID, inodeId);
  }
  v.visit(ImageElement.REPLICATION, in.readShort());
  v.visit(ImageElement.MODIFICATION_TIME, formatDate(in.readLong()));
  if(NameNodeLayoutVersion.supports(Feature.FILE_ACCESS_TIME, imageVersion))
    v.visit(ImageElement.ACCESS_TIME, formatDate(in.readLong()));
  v.visit(ImageElement.BLOCK_SIZE, in.readLong());
  int numBlocks = in.readInt();

  processBlocks(in, v, numBlocks, skipBlocks);
  
  if (numBlocks >= 0) { // File
    if (supportSnapshot) {
      // make sure subtreeMap only contains entry for directory
      subtreeMap.remove(inodeId);
      // process file diffs
      processFileDiffList(in, v, parentName);
      if (isSnapshotCopy) {
        boolean underConstruction = in.readBoolean();
        if (underConstruction) {
          v.visit(ImageElement.CLIENT_NAME,
              FSImageSerialization.readString(in));
          v.visit(ImageElement.CLIENT_MACHINE,
              FSImageSerialization.readString(in));
        }
      }
    }
    processPermission(in, v);
  } else if (numBlocks == -1) { // Directory
    if (supportSnapshot && supportInodeId) {
      dirNodeMap.put(inodeId, pathName);
    }
    v.visit(ImageElement.NS_QUOTA, numBlocks == -1 ? in.readLong() : -1);
    if (NameNodeLayoutVersion.supports(Feature.DISKSPACE_QUOTA, imageVersion))
      v.visit(ImageElement.DS_QUOTA, numBlocks == -1 ? in.readLong() : -1);
    if (supportSnapshot) {
      boolean snapshottable = in.readBoolean();
      if (!snapshottable) {
        boolean withSnapshot = in.readBoolean();
        v.visit(ImageElement.IS_WITHSNAPSHOT_DIR, Boolean.toString(withSnapshot));
      } else {
        v.visit(ImageElement.IS_SNAPSHOTTABLE_DIR, Boolean.toString(snapshottable));
      }
    }
    processPermission(in, v);
  } else if (numBlocks == -2) {
    v.visit(ImageElement.SYMLINK, Text.readString(in));
    processPermission(in, v);
  } else if (numBlocks == -3) { // reference node
    final boolean isWithName = in.readBoolean();
    int snapshotId = in.readInt();
    if (isWithName) {
      v.visit(ImageElement.SNAPSHOT_LAST_SNAPSHOT_ID, snapshotId);
    } else {
      v.visit(ImageElement.SNAPSHOT_DST_SNAPSHOT_ID, snapshotId);
    }
    
    final boolean firstReferred = in.readBoolean();
    if (firstReferred) {
      // if a subtree is linked by multiple "parents", the corresponding dir
      // must be referred by a reference node. we put the reference node into
      // the subtreeMap here and let its value be false. when we later visit
      // the subtree for the first time, we change the value to true.
      subtreeMap.put(inodeId, false);
      v.visitEnclosingElement(ImageElement.SNAPSHOT_REF_INODE);
      processINode(in, v, skipBlocks, parentName, isSnapshotCopy);
      v.leaveEnclosingElement();  // referred inode    
    } else {
      v.visit(ImageElement.SNAPSHOT_REF_INODE_ID, in.readLong());
    }
  }

  v.leaveEnclosingElement(); // INode
}
 
Example 16
Source File: ZygoteProcess.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Sends an argument list to the zygote process, which starts a new child
 * and returns the child's pid. Please note: the present implementation
 * replaces newlines in the argument list with spaces.
 * 
 * 向 Zygote 进程发送参数列表,请求新建一个子进程并返回子进程的 pid
 *
 * @throws ZygoteStartFailedEx if process start failed for any reason
 */
@GuardedBy("mLock")
private static Process.ProcessStartResult zygoteSendArgsAndGetResult(
        ZygoteState zygoteState, ArrayList<String> args)
        throws ZygoteStartFailedEx {
    try {
        // Throw early if any of the arguments are malformed. This means we can
        // avoid writing a partial response to the zygote.
        int sz = args.size();
        for (int i = 0; i < sz; i++) {
            if (args.get(i).indexOf('\n') >= 0) {
                throw new ZygoteStartFailedEx("embedded newlines not allowed");
            }
        }

        /**
         * See com.android.internal.os.SystemZygoteInit.readArgumentList()
         * Presently the wire format to the zygote process is:
         * a) a count of arguments (argc, in essence)
         * b) a number of newline-separated argument strings equal to count
         *
         * After the zygote process reads these it will write the pid of
         * the child or -1 on failure, followed by boolean to
         * indicate whether a wrapper process was used.
         */
        final BufferedWriter writer = zygoteState.writer;
        final DataInputStream inputStream = zygoteState.inputStream;

        writer.write(Integer.toString(args.size()));
        writer.newLine();

        // 向 zygote 进程发送参数
        for (int i = 0; i < sz; i++) {
            String arg = args.get(i);
            writer.write(arg);
            writer.newLine();
        }

        writer.flush();

        // Should there be a timeout on this?
        // 是不是应该有一个超时时间?
        Process.ProcessStartResult result = new Process.ProcessStartResult();

        // Always read the entire result from the input stream to avoid leaving
        // bytes in the stream for future process starts to accidentally stumble
        // upon.
        // 读取 zygote 进程返回的子进程 pid
        result.pid = inputStream.readInt();
        result.usingWrapper = inputStream.readBoolean();

        if (result.pid < 0) { // pid 小于 0 ,fork 失败
            throw new ZygoteStartFailedEx("fork() failed");
        }
        return result;
    } catch (IOException ex) {
        zygoteState.close();
        throw new ZygoteStartFailedEx(ex);
    }
}
 
Example 17
Source File: ModuleManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ModuleDataCache() {
    InputStream is = Stamps.getModulesJARs().asStream(CACHE);
    Map<String,byte[]> map = null;
    Map<String,Boolean> osgi = null;
    Map<String,String> cnbs = null;
    Map<String,String> frags = null;
    Set<String> toEn = null;
    List<String> toWi = null;
    int cnt = -1;
    char otherChar = File.separatorChar == '/' ? '\\' : '/';
    if (is != null) try {
        DataInputStream dis = new DataInputStream(is);
        
        String locale = dis.readUTF();
        String branding = dis.readUTF();
        
        if (!Locale.getDefault().toString().equals(locale)) {
            throw new IOException();
        }
        if (!branding.equals(nonNullBranding())) {
            throw new IOException();
        }
        
        map = new HashMap<String, byte[]>();
        osgi = new HashMap<String, Boolean>();
        cnbs = new HashMap<String, String>();
        frags = new HashMap<String, String>();
        cnt = dis.readInt();
        for (;;) {
            String path = Stamps.readRelativePath(dis).replace(otherChar, File.separatorChar);
            if (path.isEmpty()) {
                break;
            }
            boolean isOSGi = dis.readBoolean();
            osgi.put(path, isOSGi);
            cnbs.put(path, dis.readUTF());
            int len = dis.readInt();
            byte[] data = new byte[len];
            dis.readFully(data);
            map.put(path, data);
            String fhost = dis.readUTF();
            if (fhost != null) {
                // retain empty Strings, as they count as "known data".
                frags.put(path, fhost);
            }
        }
        toEn = readCnbs(dis, new HashSet<String>());
        toWi = readCnbs(dis, new ArrayList<String>());
        dis.close();
    } catch (IOException ex) {
        Util.err.log(Level.FINE, "Cannot read " + Places.getCacheSubfile(CACHE), ex);
        map = null;
        osgi = null;
        cnbs = null;
        toEn = null;
        toWi = null;
        frags = null;
    }
    path2Data = map;
    path2OSGi = osgi;
    path2Cnb = cnbs;
    path2Fragment = frags;
    toEnable = toEn;
    willEnable = toWi;
    moduleCount = cnt;
    if (map == null) {
        reset();
    }
}
 
Example 18
Source File: Resources.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
Timeline readTimeline(DataInputStream input) throws IOException {
    int duration = input.readInt();
    int width = input.readInt();
    int height = input.readInt();
    AnimationObject[] animations = new AnimationObject[input.readShort()];
    int alen = animations.length;
    for(int iter = 0 ; iter < alen ; iter++) {
        String name = input.readUTF();
        int startTime = input.readInt();
        int animDuration = input.readInt();
        int x = input.readInt();
        int y = input.readInt();
        Image i = getImage(name);
        if(i == null) {
            animations[iter] = AnimationObject.createAnimationImage(name, this, x, y);
        } else {
            animations[iter] = AnimationObject.createAnimationImage(i, x, y);
        }
        animations[iter].setStartTime(startTime);
        animations[iter].setEndTime(startTime + animDuration);
        int frameDelay = input.readInt();
        if(frameDelay > -1) {
            int frameWidth = input.readInt();
            int frameHeight = input.readInt();
            animations[iter].defineFrames(frameWidth, frameHeight, frameDelay);
        }
        if(input.readBoolean()) {
            animations[iter].defineMotionX(input.readInt(), startTime, animDuration, x, input.readInt());
        }
        if(input.readBoolean()) {
            animations[iter].defineMotionY(input.readInt(), startTime, animDuration, y, input.readInt());
        }
        if(input.readBoolean()) {
            animations[iter].defineWidth(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
        }
        if(input.readBoolean()) {
            animations[iter].defineHeight(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
        }
        if(input.readBoolean()) {
            animations[iter].defineOpacity(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
        }
        if(input.readBoolean()) {
            animations[iter].defineOrientation(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
        }
    }
    Timeline tl = Timeline.createTimeline(duration, animations, new Dimension(width, height));
    return tl;
}
 
Example 19
Source File: WriteAheadRepositoryRecordSerde.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private void deserializeClaim(final DataInputStream in, final int serializationVersion, final StandardFlowFileRecord.Builder ffBuilder) throws IOException {
    // determine current Content Claim.
    final int claimExists = in.read();
    if (claimExists == 1) {
        final String claimId;
        if (serializationVersion < 4) {
            claimId = String.valueOf(in.readLong());
        } else {
            claimId = readString(in);
        }

        final String container = readString(in);
        final String section = readString(in);

        final long resourceOffset;
        final long resourceLength;
        if (serializationVersion < 7) {
            resourceOffset = 0L;
            resourceLength = -1L;
        } else {
            resourceOffset = in.readLong();
            resourceLength = in.readLong();
        }

        final long claimOffset = in.readLong();

        final boolean lossTolerant;
        if (serializationVersion >= 3) {
            lossTolerant = in.readBoolean();
        } else {
            lossTolerant = false;
        }

        final ResourceClaim resourceClaim = claimManager.newResourceClaim(container, section, claimId, lossTolerant, false);
        final StandardContentClaim contentClaim = new StandardContentClaim(resourceClaim, resourceOffset);
        contentClaim.setLength(resourceLength);

        ffBuilder.contentClaim(contentClaim);
        ffBuilder.contentClaimOffset(claimOffset);
    } else if (claimExists == -1) {
        throw new EOFException();
    } else if (claimExists != 0) {
        throw new IOException("Claim Existence Qualifier not found in stream; found value: "
            + claimExists + " after successfully restoring " + recordsRestored + " records");
    }
}
 
Example 20
Source File: WriteAheadRepositoryRecordSerde.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void deserializeClaim(final DataInputStream in, final int serializationVersion, final StandardFlowFileRecord.Builder ffBuilder) throws IOException {
    // determine current Content Claim.
    final int claimExists = in.read();
    if (claimExists == 1) {
        final String claimId;
        if (serializationVersion < 4) {
            claimId = String.valueOf(in.readLong());
        } else {
            claimId = readString(in);
        }

        final String container = readString(in);
        final String section = readString(in);

        final long resourceOffset;
        final long resourceLength;
        if (serializationVersion < 7) {
            resourceOffset = 0L;
            resourceLength = -1L;
        } else {
            resourceOffset = in.readLong();
            resourceLength = in.readLong();
        }

        final long claimOffset = in.readLong();

        final boolean lossTolerant;
        if (serializationVersion >= 3) {
            lossTolerant = in.readBoolean();
        } else {
            lossTolerant = false;
        }

        final ResourceClaim resourceClaim = claimManager.newResourceClaim(container, section, claimId, lossTolerant, false);
        final StandardContentClaim contentClaim = new StandardContentClaim(resourceClaim, resourceOffset);
        contentClaim.setLength(resourceLength);

        ffBuilder.contentClaim(contentClaim);
        ffBuilder.contentClaimOffset(claimOffset);
    } else if (claimExists == -1) {
        throw new EOFException();
    } else if (claimExists != 0) {
        throw new IOException("Claim Existence Qualifier not found in stream; found value: "
            + claimExists + " after successfully restoring " + recordsRestored + " records");
    }
}