나는 HashMap
을 보유하고 있으며 빠르게 액세스하고 싶습니다. 나는 log.info 내가 내지도에서 231,045 항목이 있음을 보여줍니다 내가 성공적으로컴파일 된 jar에 kryo 개체를 저장 하시겠습니까?
Input input = new Input(new FileInputStream("src/main/resources/locations50K.kryo"));
Map<String, Location> locationMap;
locationMap = kryo.readObject(input, HashMap.class);
input.close();
log.info(locationMap.size());
와 역 직렬화 할 수있는 객체
Kryo kryo = new Kryo();
MapSerializer serializer = new MapSerializer();
kryo.register(Location.class);
kryo.register(HashMap.class, serializer);
Output output = new Output(new FileOutputStream("src/main/resources/locations50K.kryo"));
kryo.writeObject(output, locationMap);
output.close();
를 직렬화하는 Kryo를 사용합니다.
이제 Maven을 사용하고 있습니다. * -jar-with-dependencies.jar을 컴파일 한 후, .kryo 파일에 액세스하고 싶습니다. 그래서, 오히려 src/main/resources/
에서 읽는 FileInputStream
보다 나는 log.error 결코 보여주지 MyClass.class.getResourceAsStream
InputStream isr = MyClass.class.getResourceAsStream("/locations50K.kryo");
if(isr == null)
log.error("null input");
Input input = new Input(isr);
locationMap = kryo.readObject(input, HashMap.class);
input.close();
log.info(locationMap.size());
사용하고 log.info는 내지도에서 0 항목이 말했다. 왜? isr
이 null이 아니므로 Kryo는이를 읽는 중입니다. Kryo는이를 deserialize하는 것처럼 보이지 않으며 오류를 제공하지 않습니다.