org.nustaq.serialization.FSTObjectInput Java Examples

The following examples show how to use org.nustaq.serialization.FSTObjectInput. 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: FstExample.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();

    SomeMediumClass mediumClass = new SomeMediumClass();
    byte barray[] = conf.asByteArray(mediumClass);
    System.out.println(barray.length);
    SomeMediumClass object = (SomeMediumClass)conf.asObject(barray);
    System.out.println(object);


    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    FSTObjectOutput output = new FSTObjectOutput(outputStream);
    output.writeObject(mediumClass);
    output.close();

    FSTObjectInput input = new FSTObjectInput(new ByteArrayInputStream(outputStream.toByteArray()));
    object = (SomeMediumClass)input.readObject(SomeMediumClass.class);
    System.out.println(object);
}
 
Example #2
Source File: FstSerializationRedisSerializer.java    From jetlinks-community with Apache License 2.0 5 votes vote down vote up
@Override
@SneakyThrows
public Object deserialize(byte[] bytes) throws SerializationException {

    try (FSTObjectInput input = configuration.get().getObjectInput(bytes)) {
        return input.readObject();
    }
}
 
Example #3
Source File: Serializer.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
public static <T> T readObject(InputStream input, Class<T> clazz) throws Exception {
  FSTObjectInput in = getFST().getObjectInput(input);
  Object obj = in.readObject(clazz);
  input.close();
  if (isNull(obj)) {
    return null;
  }
  return clazz.cast(obj);
}
 
Example #4
Source File: Parser.java    From science-parse with Apache License 2.0 5 votes vote down vote up
public static ModelComponents loadModelComponents(
  final DataInputStream dis,
  String dataVersion
) throws IOException {
  IOUtils.ensureVersionMatch(dis, dataVersion);
  val stateSpace = StateSpace.load(dis);
  Indexer<String> nodeFeatures = Indexer.load(dis);
  Indexer<String> edgeFeatures = Indexer.load(dis);
  Vector weights = DenseVector.of(IOUtils.loadDoubles(dis));

  logger.debug("Loading ParserLMFeatures");
  final ParserLMFeatures plf;
  try(final FSTObjectInput in = new FSTObjectInput(dis)) {
    try {
      plf = (ParserLMFeatures) in.readObject();
    } catch (final ClassNotFoundException e) {
      throw new IOException("Model file contains unknown class.", e);
    }
  }
  if(plf != null && logger.isDebugEnabled())
    plf.logState();

  val predExtractor = new PDFPredicateExtractor(plf);
  val featureEncoder = new CRFFeatureEncoder<String, PaperToken, String>
          (predExtractor, stateSpace, nodeFeatures, edgeFeatures);
  val weightsEncoder = new CRFWeightsEncoder<String>(stateSpace, nodeFeatures.size(), edgeFeatures.size());
  val model = new CRFModel<String, PaperToken, String>(featureEncoder, weightsEncoder, weights);
  return new ModelComponents(predExtractor, featureEncoder, weightsEncoder, model);
}
 
Example #5
Source File: FSTPeerAddressSerializer.java    From Hive2Hive with MIT License 5 votes vote down vote up
@Override
public Object instantiate(Class objectClass, FSTObjectInput in, FSTClazzInfo serializationInfo, FSTFieldInfo referencee,
		int streamPosition) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
	byte[] buf = new byte[in.readInt()];
	in.read(buf);
	PeerAddress address = new PeerAddress(buf);
	in.registerObject(address, streamPosition, serializationInfo, referencee);
	return address;
}
 
Example #6
Source File: FstFactory.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
public FSTObjectInput getObjectInput(InputStream inputStream) {
    return conf.getObjectInput(inputStream);
}
 
Example #7
Source File: FSTObjectReader.java    From joyrpc with Apache License 2.0 4 votes vote down vote up
public FSTObjectReader(FSTObjectInput input) {
    super(input);
}
 
Example #8
Source File: FstFactory.java    From JobX with Apache License 2.0 4 votes vote down vote up
public FSTObjectInput getObjectInput(InputStream inputStream) {
    return conf.getObjectInput(inputStream);
}
 
Example #9
Source File: FstFactory.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public FSTObjectInput getObjectInput(InputStream inputStream) {
    return conf.getObjectInput(inputStream);
}
 
Example #10
Source File: FstFactory.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public FSTObjectInput getObjectInput(InputStream inputStream) {
    return conf.getObjectInput(inputStream);
}
 
Example #11
Source File: ExtractReferences.java    From science-parse with Apache License 2.0 4 votes vote down vote up
public ExtractReferences(
    final InputStream is,
    final DataInputStream bibCRFModel,
    final InputStream gazCacheInputStream
) throws IOException {
  if(gazCacheInputStream != null) {
    try(final FSTObjectInput in = new FSTObjectInput(gazCacheInputStream)) {
      cr = (CheckReferences)in.readObject();
    } catch(final Exception e) {
      log.warn("Could not load gazetteer from cache. Loading it slowly instead.", e);
    }
  }

  if(cr == null)
    cr = new CheckReferences(is);

  extractors = new ArrayList<>();
  
  if(bibCRFModel != null) {
    final CRFModel<String, String, String> bibCRF = loadModel(bibCRFModel);
    bibCRFRecordParser = new CRFBibRecordParser(bibCRF);
    extractors.addAll(Arrays.asList(
        new NumberCloseParen(new Class [] {
            NumberCloseParenBibRecordParser.class,
            CRFBibRecordParser.class}),
        new BracketNumber(new Class [] {
            BracketNumberInitialsQuotedBibRecordParser.class,
            CRFBibRecordParser.class}),
        new NamedYear(new Class [] {
            NamedYearBibRecordParser.class,
            CRFBibRecordParser.class}),
        new NamedYear(new Class [] {
            NamedYearInParensBibRecordParser.class,
            CRFBibRecordParser.class}),
        new NumberDot(new Class [] {
            NumberDotYearParensBibRecordParser.class,
            CRFBibRecordParser.class}),
        new NumberDot(new Class [] {
            NumberDotAuthorNoTitleBibRecordParser.class,
            CRFBibRecordParser.class}),
        new NumberDot(new Class [] {
            NumberDotYearNoParensBibRecordParser.class,
            CRFBibRecordParser.class}),
        new BracketNumber(new Class [] {
            BracketNumberInitialsYearParensCOMMAS.class,
            CRFBibRecordParser.class}),
        new BracketNumber(new Class [] {
            BracketNumberBibRecordParser.class,
            CRFBibRecordParser.class}),
        new BracketName(new Class [] {
            BracketNameBibRecordParser.class,
            CRFBibRecordParser.class})
    ));
    extractors.addAll(Arrays.asList(
      new BracketNumber(new Class [] {CRFBibRecordParser.class}),
      new NumberDot(new Class [] {CRFBibRecordParser.class}),
      new NumberDotNaturalLineBreaks(new Class [] {CRFBibRecordParser.class}),
      new NamedYear(new Class [] {CRFBibRecordParser.class}),
      new BracketName(new Class [] {CRFBibRecordParser.class})));
  } else {
    bibCRFRecordParser = null;
    extractors.addAll(Arrays.asList(
        new BracketNumber(new Class [] {BracketNumberInitialsQuotedBibRecordParser.class}),
        new NamedYear(new Class [] {NamedYearBibRecordParser.class}),
        new NamedYear(new Class [] {NamedYearInParensBibRecordParser.class}),
        new NumberDot(new Class [] {NumberDotYearParensBibRecordParser.class}),
        new NumberDot(new Class [] {NumberDotAuthorNoTitleBibRecordParser.class}),
        new NumberDot(new Class [] {NumberDotYearNoParensBibRecordParser.class}),
        new BracketNumber(new Class [] {BracketNumberInitialsYearParensCOMMAS.class}),
        new BracketNumber(new Class [] {BracketNumberBibRecordParser.class}),
        new BracketName(new Class [] {BracketNameBibRecordParser.class})));
  }
}
 
Example #12
Source File: Parameters.java    From htm.java with GNU Affero General Public License v3.0 4 votes vote down vote up
public Parameters readForNetwork(FSTObjectInput in) throws Exception {
    Parameters result = (Parameters)in.readObject(Parameters.class);
    return result;
}