package com.jimjh.kryo;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * Writes and reads a POJO from disk.
 *
 * @author Jim Lim - jim@quixey.com
 */
public class SimpleIO {

  private static final Logger LOGGER = LoggerFactory.getLogger(SimpleIO.class);

  /**
   * @param args command-line args, ignored for now
   */
  public static void main(String[] args) throws IOException {
    POJO object = POJO.create();
    Kryo kryo = new Kryo();

    Path scratch = Files.createTempDirectory("kryo");
    String file = scratch.resolve("file.io").toString();

    try (Output output = new Output(new FileOutputStream(file))) {
      kryo.writeObject(output, object);
      LOGGER.info("Wrote object to {}", file);
    }

    try (Input input = new Input(new FileInputStream(file))) {
      POJO read = kryo.readObject(input, POJO.class);
      LOGGER.info("Read object from {}", file);
    }
  }
}

@@ -668,16 +668,108 @@
 ption %7B%0A
+    ioToFile();%0A    ioToArray();%0A  %7D%0A%0A  private static void ioToFile() throws IOException %7B%0A
     POJO
@@ -1269,11 +1269,530 @@
    %7D%0A  %7D
+%0A%0A  private static void ioToArray() throws IOException %7B%0A    POJO object = POJO.create();%0A    Kryo kryo = new Kryo();%0A%0A    byte%5B%5D buffer;%0A%0A    try (Output output = new Output(1024 * 1024)) %7B%0A      kryo.writeObject(output, object);%0A      buffer = output.toBytes();%0A      LOGGER.info(%22Wrote object #%7B%7D%22, System.identityHashCode(object));%0A    %7D%0A%0A    try (Input input = new Input(buffer)) %7B%0A      POJO read = kryo.readObject(input, POJO.class);%0A      LOGGER.info(%22Read object #%7B%7D%22, System.identityHashCode(read));%0A    %7D%0A  %7D
 %0A%7D%0A

add #ioToArray