Skip to content

Commit

Permalink
[SPARK-20284][CORE] Make {Des,S}erializationStream extend Closeable
Browse files Browse the repository at this point in the history
## 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 <[email protected]>

Closes apache#17598 from superbobry/compression-stream-closeable.
  • Loading branch information
Sergei Lebedev authored and Mingjie Tang committed Apr 18, 2017
1 parent 599a49b commit f8c93e9
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ abstract class SerializerInstance {
* A stream for writing serialized objects.
*/
@DeveloperApi
abstract class SerializationStream {
abstract class SerializationStream extends Closeable {
/** The most general-purpose method to write an object. */
def writeObject[T: ClassTag](t: T): SerializationStream
/** Writes the object representing the key of a key-value pair. */
def writeKey[T: ClassTag](key: T): SerializationStream = writeObject(key)
/** Writes the object representing the value of a key-value pair. */
def writeValue[T: ClassTag](value: T): SerializationStream = writeObject(value)
def flush(): Unit
def close(): Unit
override def close(): Unit

def writeAll[T: ClassTag](iter: Iterator[T]): SerializationStream = {
while (iter.hasNext) {
Expand All @@ -149,14 +149,14 @@ abstract class SerializationStream {
* A stream for reading serialized objects.
*/
@DeveloperApi
abstract class DeserializationStream {
abstract class DeserializationStream extends Closeable {
/** The most general-purpose method to read an object. */
def readObject[T: ClassTag](): T
/** Reads the object representing the key of a key-value pair. */
def readKey[T: ClassTag](): T = readObject[T]()
/** Reads the object representing the value of a key-value pair. */
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
Expand Down

0 comments on commit f8c93e9

Please sign in to comment.