Skip to content
Snippets Groups Projects
Commit a4293c28 authored by Sergei Lebedev's avatar Sergei Lebedev Committed by Sean Owen
Browse files

[SPARK-20284][CORE] Make {Des,S}erializationStream extend Closeable

## What changes were proposed in this pull request?

This PR allows to use `SerializationStream` and `DeserializationStream` in try-with-resources.

## How was this patch tested?

`core` unit tests.

Author: Sergei Lebedev <s.lebedev@criteo.com>

Closes #17598 from superbobry/compression-stream-closeable.
parent 095d1cb3
No related branches found
No related tags found
No related merge requests found
...@@ -125,7 +125,7 @@ abstract class SerializerInstance { ...@@ -125,7 +125,7 @@ abstract class SerializerInstance {
* A stream for writing serialized objects. * A stream for writing serialized objects.
*/ */
@DeveloperApi @DeveloperApi
abstract class SerializationStream { abstract class SerializationStream extends Closeable {
/** The most general-purpose method to write an object. */ /** The most general-purpose method to write an object. */
def writeObject[T: ClassTag](t: T): SerializationStream def writeObject[T: ClassTag](t: T): SerializationStream
/** Writes the object representing the key of a key-value pair. */ /** Writes the object representing the key of a key-value pair. */
...@@ -133,7 +133,7 @@ abstract class SerializationStream { ...@@ -133,7 +133,7 @@ abstract class SerializationStream {
/** Writes the object representing the value of a key-value pair. */ /** Writes the object representing the value of a key-value pair. */
def writeValue[T: ClassTag](value: T): SerializationStream = writeObject(value) def writeValue[T: ClassTag](value: T): SerializationStream = writeObject(value)
def flush(): Unit def flush(): Unit
def close(): Unit override def close(): Unit
def writeAll[T: ClassTag](iter: Iterator[T]): SerializationStream = { def writeAll[T: ClassTag](iter: Iterator[T]): SerializationStream = {
while (iter.hasNext) { while (iter.hasNext) {
...@@ -149,14 +149,14 @@ abstract class SerializationStream { ...@@ -149,14 +149,14 @@ abstract class SerializationStream {
* A stream for reading serialized objects. * A stream for reading serialized objects.
*/ */
@DeveloperApi @DeveloperApi
abstract class DeserializationStream { abstract class DeserializationStream extends Closeable {
/** The most general-purpose method to read an object. */ /** The most general-purpose method to read an object. */
def readObject[T: ClassTag](): T def readObject[T: ClassTag](): T
/** Reads the object representing the key of a key-value pair. */ /** Reads the object representing the key of a key-value pair. */
def readKey[T: ClassTag](): T = readObject[T]() def readKey[T: ClassTag](): T = readObject[T]()
/** Reads the object representing the value of a key-value pair. */ /** Reads the object representing the value of a key-value pair. */
def readValue[T: ClassTag](): T = readObject[T]() def readValue[T: ClassTag](): T = readObject[T]()
def close(): Unit override def close(): Unit
/** /**
* Read the elements of this stream through an iterator. This can only be called once, as * Read the elements of this stream through an iterator. This can only be called once, as
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment