Giter Site home page Giter Site logo

【JAVA】deserialize class not found USE withRefTracking(true).requireClassRegistration(false).withCompatibleMode(CompatibleMode.COMPATIBLE).buildThreadSafeFury() about incubator-fury HOT 1 CLOSED

weijiang157152688 avatar weijiang157152688 commented on June 6, 2024
【JAVA】deserialize class not found USE withRefTracking(true).requireClassRegistration(false).withCompatibleMode(CompatibleMode.COMPATIBLE).buildThreadSafeFury()

from incubator-fury.

Comments (1)

chaokunyang avatar chaokunyang commented on June 6, 2024

I can run this successfully locally:
image

Here is my code:

package org.apache.fury;

import lombok.Data;
import org.apache.fury.config.CompatibleMode;
import org.apache.fury.logging.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;

public class Test {
  @Data
  public static class AssignDetailInfoLog {
    String id;
    AssignType  type;

  }



  public enum AssignType {
    DEFAULT;
  }



  public static class FuryUtils {
    private static final ThreadSafeFury fury;

    public FuryUtils() {
    }

    public static <T> byte[] serialize(T t) {
      return fury.serialize(t);
    }

    public static Object zeroCopyDeserialize(byte[] byteBuffer) {
      return fury.deserialize(byteBuffer);
    }

    public static Object zeroCopyDeserialize(ByteBuffer byteBuffer) {
      return fury.deserialize(byteBuffer);
    }

    static {
      fury = Fury.builder().withRefTracking(true).requireClassRegistration(false).withCompatibleMode(CompatibleMode.COMPATIBLE).buildThreadSafeFury();
      LoggerFactory.disableLogging();
    }
  }

  public static void main(String[] args) throws IOException {

    // read
    read();

//        write();

  }

  public static void write() throws IOException {
    AssignDetailInfoLog assignDetailInfoLog = new AssignDetailInfoLog();
    assignDetailInfoLog.setType(AssignType.DEFAULT);
    assignDetailInfoLog.setId("dsa");
    byte[] data = FuryUtils.serialize(assignDetailInfoLog);
    saveToFile("test_file", data);
  }

  public static void read() throws IOException {
    write();
    // read
    byte[] data = readFileToBytes("test_file");
    FuryUtils.zeroCopyDeserialize(data);

  }

  public static void saveToFile(String fileName, byte[] data) {
    try (FileOutputStream outputStream = new FileOutputStream(fileName)) {
      outputStream.write(data);  // 写入byte[]
      System.out.println("Data has been written to " + fileName);
    } catch (IOException e) {
      e.printStackTrace();
    }

  }

  public static byte[] readFileToBytes(String filePath) {
    try {
      return Files.readAllBytes(new File(filePath).toPath());
    } catch (Exception e) {
      return null;
    }
  }
}

from incubator-fury.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.