Esempio n. 1
0
 public static BlurAnalyzer create(InputStream inputStream) throws IOException {
   TMemoryInputTransport trans = new TMemoryInputTransport(getBytes(inputStream));
   TJSONProtocol protocol = new TJSONProtocol(trans);
   AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition();
   try {
     analyzerDefinition.read(protocol);
   } catch (TException e) {
     throw new RuntimeException(e);
   }
   trans.close();
   return new BlurAnalyzer(analyzerDefinition);
 }
 @SuppressWarnings("unchecked")
 private <T extends TBase<?, ?>> T fromBytes(byte[] data, Class<T> clazz) {
   try {
     if (data == null) {
       return null;
     }
     TBase<?, ?> base = clazz.newInstance();
     TMemoryInputTransport trans = new TMemoryInputTransport(data);
     TJSONProtocol protocol = new TJSONProtocol(trans);
     base.read(protocol);
     trans.close();
     return (T) base;
   } catch (InstantiationException e) {
     throw new RuntimeException(e);
   } catch (IllegalAccessException e) {
     throw new RuntimeException(e);
   } catch (TException e) {
     throw new RuntimeException(e);
   }
 }
    /**
     * Builds Thrift object from the raw bytes returned by RCFile reader.
     *
     * @throws TException
     */
    @SuppressWarnings({"unchecked", "rawtypes"})
    public TBase<?, ?> getCurrentThriftValue()
        throws IOException, InterruptedException, TException {

      BytesRefArrayWritable byteRefs = getCurrentBytesRefArrayWritable();

      if (byteRefs == null) {
        return null;
      }

      TBase tObj = tDesc.newThriftObject();

      for (int i = 0; i < knownRequiredFields.size(); i++) {
        BytesRefWritable buf = byteRefs.get(columnsBeingRead.get(i));
        if (buf.getLength() > 0) {
          memTransport.reset(buf.getData(), buf.getStart(), buf.getLength());

          Field field = knownRequiredFields.get(i);
          tObj.setFieldValue(field.getFieldIdEnum(), ThriftUtils.readFieldNoTag(tProto, field));
        }
        // else no need to set default value since any default value
        // would have been serialized when this record was written.
      }

      // parse unknowns column if required
      if (readUnknownsColumn) {
        int last = columnsBeingRead.get(columnsBeingRead.size() - 1);
        BytesRefWritable buf = byteRefs.get(last);
        if (buf.getLength() > 0) {
          memTransport.reset(buf.getData(), buf.getStart(), buf.getLength());
          tObj.read(tProto);
        }
      }

      return tObj;
    }
    /** Actually invoke the method signified by this FrameBuffer. */
    public void invoke() {
      frameTrans_.reset(buffer_.array());
      response_.reset();

      try {
        if (eventHandler_ != null) {
          eventHandler_.processContext(context_, inTrans_, outTrans_);
        }
        processorFactory_.getProcessor(inTrans_).process(inProt_, outProt_);
        responseReady();
        return;
      } catch (TException te) {
        Log.w("Thrift", "Exception while invoking!", te);
      } catch (Throwable t) {
        Log.e("Protocol", "Unexpected throwable while invoking!", t);
      }
      // This will only be reached when there is a throwable.
      state_ = FrameBufferState.AWAITING_CLOSE;
      requestSelectInterestChange();
    }