com.esotericsoftware.kryo.io.Output.close()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中com.esotericsoftware.kryo.io.Output.close()方法的一些代码示例,展示了Output.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Output.close()方法的具体详情如下:
包路径:com.esotericsoftware.kryo.io.Output
类名称:Output
方法名:close

Output.close介绍

[英]Flushes any buffered bytes and closes the underlying OutputStream, if any.
[中]刷新所有缓冲字节并关闭底层OutputStream(如果有)。

代码示例

代码示例来源:origin: apache/hive

private static byte[] serializeObjectToKryo(Serializable object) {
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 Output output = new Output(baos);
 Kryo kryo = borrowKryo();
 try {
  kryo.writeObject(output, object);
 } finally {
  releaseKryo(kryo);
 }
 output.close();
 return baos.toByteArray();
}

代码示例来源:origin: apache/hive

public static byte[] serialize(Object object) {
 ByteArrayOutputStream stream = new ByteArrayOutputStream();
 Output output = new Output(stream);
 Kryo kryo = SerializationUtilities.borrowKryo();
 kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
 try {
  kryo.writeObject(output, object);
 } finally {
  SerializationUtilities.releaseKryo(kryo);
 }
 output.close(); // close() also calls flush()
 return stream.toByteArray();
}

代码示例来源:origin: apache/hive

/**
 * @param plan Usually of type MapredWork, MapredLocalWork etc.
 * @param out stream in which serialized plan is written into
 */
private static void serializeObjectByKryo(Kryo kryo, Object plan, OutputStream out) {
 Output output = new Output(out);
 kryo.setClassLoader(Utilities.getSessionSpecifiedClassLoader());
 kryo.writeObject(output, plan);
 output.close();
}

代码示例来源:origin: yu199195/Raincat

@Override
public void serialize(final OutputStream output, final Object object) throws IOException {
  Kryo kryo = pool.borrow();
  Output out = new Output(output);
  kryo.writeClassAndObject(out, object);
  out.close();
  output.close();
  pool.release(kryo);
}

代码示例来源:origin: apache/flink

output.close();

代码示例来源:origin: apache/hive

SerializationUtilities.releaseKryo(kryo);
 output.close();
 return true;
} catch (IOException e) {

代码示例来源:origin: apache/hive

public synchronized void clear() {
 writeCursor = readCursor = rowsInReadBuffer = 0;
 readBufferUsed = false;
 if (parentFile != null) {
  if (input != null) {
   try {
    input.close();
   } catch (Throwable ignored) {
   }
   input = null;
  }
  if (output != null) {
   try {
    output.close();
   } catch (Throwable ignored) {
   }
   output = null;
  }
  try {
   FileUtil.fullyDelete(parentFile);
  } catch (Throwable ignored) {
  }
  parentFile = null;
  tmpFile = null;
 }
}

代码示例来源:origin: apache/hive

public void clear() {
 readCursor = rowsInReadBuffer = rowsOnDisk = 0;
 readBufferUsed = false;
 if (parentDir != null) {
  if (input != null) {
   try {
    input.close();
   } catch (Throwable ignored) {
   }
   input = null;
  }
  if (output != null) {
   try {
    output.close();
   } catch (Throwable ignored) {
   }
   output = null;
  }
  try {
   FileUtil.fullyDelete(parentDir);
  } catch (Throwable ignored) {
  }
  parentDir = null;
  tmpFile = null;
 }
}

代码示例来源:origin: apache/hive

public void clear() {
 readCursor = rowsInReadBuffer = rowsOnDisk = 0;
 readBufferUsed = false;
 if (parentDir != null) {
  if (input != null) {
   try {
    input.close();
   } catch (Throwable ignored) {
   }
   input = null;
  }
  if (output != null) {
   try {
    output.close();
   } catch (Throwable ignored) {
   }
   output = null;
  }
  try {
   FileUtil.fullyDelete(parentDir);
  } catch (Throwable ignored) {
  }
  parentDir = null;
  tmpFile = null;
 }
}

代码示例来源:origin: redisson/redisson

@Override
  public ByteBuf encode(Object in) throws IOException {
    Kryo kryo = null;
    ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
    try {
      ByteBufOutputStream baos = new ByteBufOutputStream(out);
      Output output = new Output(baos);
      kryo = kryoPool.get();
      kryo.writeClassAndObject(output, in);
      output.close();
      return baos.buffer();
    } catch (Exception e) {
      out.release();
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      }
      throw new RedissonKryoCodecException(e);
    } finally {
      if (kryo != null) {
        kryoPool.yield(kryo);
      }
    }
  }
};

代码示例来源:origin: redisson/redisson

@Override
  public ByteBuf encode(Object in) throws IOException {
    Kryo kryo = null;
    ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
    try {
      ByteBufOutputStream baos = new ByteBufOutputStream(out);
      Output output = new Output(baos);
      kryo = kryoPool.get();
      kryo.writeClassAndObject(output, in);
      output.close();
      return baos.buffer();
    } catch (Exception e) {
      out.release();
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      }
      throw new RedissonKryoCodecException(e);
    } finally {
      if (kryo != null) {
        kryoPool.yield(kryo);
      }
    }
  }
};

代码示例来源:origin: apache/hive

public static String toKryo(SearchArgument sarg) {
 Output out = new Output(4 * 1024, 10 * 1024 * 1024);
 new Kryo().writeObject(out, sarg);
 out.close();
 return Base64.encodeBase64String(out.toBytes());
}

代码示例来源:origin: apache/hive

LOG.info("Trying to spill hash partition " + partitionId + " ...");
 output.close();
 outputStream.close();
} finally {

代码示例来源:origin: opentripplanner/OpenTripPlanner

public void save(OutputStream outputStream) {
  Kryo kryo = makeKryo();
  LOG.debug("Consolidating edges...");
  Output output = new Output(outputStream);
  // this is not space efficient
  List<Edge> edges = new ArrayList<Edge>(this.countEdges());
  for (Vertex v : getVertices()) {
    // there are assumed to be no edges in an incoming list that are not
    // in an outgoing list
    edges.addAll(v.getOutgoing());
    if (v.getDegreeOut() + v.getDegreeIn() == 0)
      LOG.debug("vertex {} has no edges, it will not survive serialization.", v);
  }
  LOG.debug("Assigning vertex/edge ID numbers...");
  this.rebuildVertexAndEdgeIndices();
  LOG.debug("Writing edges...");
  kryo.writeClassAndObject(output, this);
  kryo.writeClassAndObject(output, edges);
  output.close();
  LOG.info("Graph written.");
  // Summarize serialized classes and associated serializers:
  // ((InstanceCountingClassResolver) kryo.getClassResolver()).summarize();
}

代码示例来源:origin: apache/hive

if (input == null && output != null) {
 output.close();
 output = null;

代码示例来源:origin: apache/hive

if (input == null && output != null) {
 output.close();
 output = null;

代码示例来源:origin: apache/hive

if (input == null && output != null) {
 output.close();
 output = null;

代码示例来源:origin: spring-projects/spring-integration

@Override
public void encode(final Object object, OutputStream outputStream) throws IOException {
  Assert.notNull(object, "cannot encode a null object");
  Assert.notNull(outputStream, "'outputSteam' cannot be null");
  final Output output = (outputStream instanceof Output ? (Output) outputStream : new Output(outputStream));
  this.pool.run(kryo -> {
    doEncode(kryo, object, output);
    return Void.class;
  });
  output.close();
}

代码示例来源:origin: westnordost/StreetComplete

@Override public byte[] toBytes(Object object)
{
  Output output = new Output(1024,-1);
  kryo.get().writeObject(output, object);
  output.close();
  return output.toBytes();
}

代码示例来源:origin: stackoverflow.com

Kryo kryo = new Kryo();
// #### Store to disk...
Output output = new Output(new FileOutputStream("file.bin"));
SomeClass someObject = ...
kryo.writeObject(output, someObject);
output.close();
// ### Restore from disk...
Input input = new Input(new FileInputStream("file.bin"));
SomeClass someObject = kryo.readObject(input, SomeClass.class);
input.close();

相关文章