public SerialFormat reinit()

in uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes.java [517:606]


  public SerialFormat reinit(Header h, InputStream istream, CASMgrSerializer casMgrSerializer,
          CasLoadMode casLoadMode, BinaryCasSerDes6 f6, AllowPreexistingFS allowPreexistingFS,
          TypeSystemImpl ts) throws CASRuntimeException {

    final DataInputStream dis = CommonSerDes.maybeWrapToDataInputStream(istream);

    CASMgrSerializer embeddedCasMgrSerializer = maybeReadEmbeddedTSI(h, dis);

    if (!h.isForm6() || casLoadMode == CasLoadMode.REINIT) {
      setupCasFromCasMgrSerializer(
              (null != embeddedCasMgrSerializer && embeddedCasMgrSerializer.hasIndexRepository())
                      ? embeddedCasMgrSerializer
                      : casMgrSerializer);
    }

    if (!h.isForm6() && casLoadMode == CasLoadMode.LENIENT) {
      /** Lenient deserialization not support for input of type {0}. */
      throw new CASRuntimeException(CASRuntimeException.LENIENT_NOT_SUPPORTED,
              new Object[] { h.toString() });
    }

    try {
      final boolean delta = h.isDelta;

      if (h.getSeqVersionNbr() < 2 && delta) { // is version 2 and delta
        /** Deserializing a Version 2 Delta Cas into UIMA Version 3 not supported. */
        throw new CASRuntimeException(CASRuntimeException.DESERIALIZING_V2_DELTA_V3);
      }

      if (!delta) {
        baseCas.resetNoQuestions();
      }

      // isBeforeV3 adjusts binary type numbers, and is reset with the CAS when !delta, so it must
      // be set here.
      isBeforeV3 = !h.isV3 && h.getSeqVersionNbr() < 2;

      if (h.isCompressed) {
        if (TRACE_DESER) {
          System.out.format("BinDeser version = %d%n", h.v);
        }
        if (h.form4) {
          BinaryCasSerDes4 bcsd4 = new BinaryCasSerDes4(baseCas.getTypeSystemImpl(), false);
          bcsd4.deserialize(baseCas, dis, delta, h);
          return h.typeSystemIndexDefIncluded ? SerialFormat.COMPRESSED_TSI
                  : SerialFormat.COMPRESSED;
        } else {
          // is form 6
          CASMgrSerializer cms = (embeddedCasMgrSerializer != null) ? embeddedCasMgrSerializer
                  : casMgrSerializer;
          TypeSystemImpl tsRead = (cms != null) ? cms.getTypeSystem() : null;
          if (null != tsRead) {
            tsRead = tsRead.commit(baseCas.getJCasClassLoader()); // https://issues.apache.org/jira/browse/UIMA-5598
          }

          TypeSystemImpl ts_for_decoding = (tsRead != null && embeddedCasMgrSerializer != null)
                  ? tsRead // first choice: embedded - it's always correct
                  : (ts != null) // 2nd choice is passed in ts arg, either ts or f6.getTgtTs()
                          ? ts
                          : (f6 != null && f6.getTgtTs() != null) ? f6.getTgtTs() // this is the ts
                                                                                  // passed in via
                                                                                  // BinaryCasSerDes6
                                                                                  // constructor
                                  : tsRead; // last choice: the ts read from 2nd input to load() in
                                            // CasIOUtils

          try {
            BinaryCasSerDes6 bcsd = (f6 != null) ? new BinaryCasSerDes6(f6, ts_for_decoding)
                    : new BinaryCasSerDes6(baseCas, ts_for_decoding);
            bcsd.deserializeAfterVersion(dis, delta, AllowPreexistingFS.allow);
            return h.typeSystemIndexDefIncluded ? SerialFormat.COMPRESSED_FILTERED_TSI
                    : h.typeSystemIncluded ? SerialFormat.COMPRESSED_FILTERED_TS
                            : SerialFormat.COMPRESSED_FILTERED;
          } catch (ResourceInitializationException e) {
            throw new CASRuntimeException(
                    CASRuntimeException.DESERIALIZING_COMPRESSED_BINARY_UNSUPPORTED, null, e);
          }
        }
      }

      return binaryDeserialization(h);
    } catch (IOException e) {
      String msg = e.getMessage();
      if (msg == null) {
        msg = e.toString();
      }
      throw new CASRuntimeException(CASRuntimeException.BLOB_DESERIALIZATION, msg);
    }

  }