/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.underfs.hdfs;

import org.apache.hadoop.fs.FSDataOutputStream;

import javax.annotation.concurrent.NotThreadSafe;
import java.io.IOException;
import java.io.OutputStream;

/**
 * Output stream implementation for {@link HdfsUnderFileSystem}. This class is just a wrapper on top
 * of an underlying {@link FSDataOutputStream}, except all calls to {@link #flush()} will be
 * converted to {@link FSDataOutputStream#sync()}. This is currently safe because all invocations of
 * flush intend the functionality to be sync.
 */
@NotThreadSafe
public class HdfsUnderFileOutputStream extends OutputStream {
  /** Underlying output stream. */
  final FSDataOutputStream mOut;

  /**
   * Basic constructor.
   *
   * @param out underlying stream to wrap
   */
  public HdfsUnderFileOutputStream(FSDataOutputStream out) {
    mOut = out;
  }

  @Override
  public void close() throws IOException {
    mOut.close();
  }

  @Override
  public void flush() throws IOException {
    // TODO(calvin): This functionality should be restricted to select output streams.
    mOut.sync();
  }

  @Override
  public void write(int b) throws IOException {
    mOut.write(b);
  }

  @Override
  public void write(byte[] b) throws IOException {
    mOut.write(b);
  }

  @Override
  public void write(byte[] b, int off, int len) throws IOException {
    mOut.write(b, off, len);
  }
}

@@ -652,27 +652,34 @@
 java.io.
-IOException
+FilterOutputStream
 ;%0Aimport
@@ -687,28 +687,27 @@
 java.io.
-OutputStream
+IOException
 ;%0A%0A/**%0A 
@@ -1112,16 +1112,22 @@
 extends 
+Filter
 OutputSt
@@ -1170,16 +1170,24 @@
 m. */%0A  
+private 
 final FS
@@ -1354,16 +1354,32 @@
  out) %7B%0A
+    super(out);%0A
     mOut
@@ -1395,86 +1395,8 @@
  %7D%0A%0A
-  @Override%0A  public void close() throws IOException %7B%0A    mOut.close();%0A  %7D%0A%0A
   @O
@@ -1557,293 +1557,7 @@
 %0A  %7D
-%0A%0A  @Override%0A  public void write(int b) throws IOException %7B%0A    mOut.write(b);%0A  %7D%0A%0A  @Override%0A  public void write(byte%5B%5D b) throws IOException %7B%0A    mOut.write(b);%0A  %7D%0A%0A  @Override%0A  public void write(byte%5B%5D b, int off, int len) throws IOException %7B%0A    mOut.write(b, off, len);%0A  %7D
 %0A%7D%0A

Clean up hdfs output stream.