DFSOutputStream extends FSOutputSummer implements Syncable, CanSetDropBehind, StreamCapabilities { @Override public synchronized void close() throws IOException { TraceScope scope = dfsClient.newPathTraceScope("DFSOutputStream#close", src); try { closeImpl(); } finally { scope.close(); } } private  DFSOutputStream(DFSClient dfsClient, String src, Progressable progress,
      HdfsFileStatus stat, DataChecksum checksum); protected  DFSOutputStream(DFSClient dfsClient, String src, HdfsFileStatus stat,
      EnumSet<CreateFlag> flag, Progressable progress,
      DataChecksum checksum, String[] favoredNodes,
      EncodingPolicy policy, final int dbFileMaxSize, boolean forceClientToWriteSFToDisk); private  DFSOutputStream(DFSClient dfsClient, String src,
      EnumSet<CreateFlag> flags, Progressable progress, LocatedBlock lastBlock,
      HdfsFileStatus stat, DataChecksum checksum, final int dbFileMaxSize, boolean forceClientToWriteSFToDisk,
      String[] favoredNodes); private  DFSOutputStream(DFSClient dfsClient, String src, 
                          Progressable progress, HdfsFileStatus stat, LocatedBlock lb, DataChecksum checksum); @VisibleForTesting synchronized DatanodeInfo[] getPipeline(); @Deprecated void sync(); @Override boolean hasCapability(String capability); @Override void hflush(); @Override void hsync(); void hsync(EnumSet<SyncFlag> syncFlags); @Deprecated synchronized int getNumCurrentReplicas(); synchronized int getCurrentBlockReplication(); @Override synchronized void close(); @VisibleForTesting void setArtificialSlowdown(long period); @VisibleForTesting synchronized void setChunksPerPacket(int value); long getInitialLen(); FileEncryptionInfo getFileEncryptionInfo(); @Override void setDropBehind(Boolean dropBehind); @VisibleForTesting long getFileId(); void enableParityStream(int stripeLength, int parityLength,
                                 String sourceFile); Collection<DatanodeInfo> getUsedNodes(); void setParityStripeNodesForNextStripe(Collection<DatanodeInfo> locations); void enableSourceStream(int stripeLength); static final Log LOG; }
@Test public void testCloseTwice() throws IOException { DistributedFileSystem fs = cluster.getFileSystem(); FSDataOutputStream os = fs.create(new Path("/test")); DFSOutputStream dos = (DFSOutputStream) Whitebox.getInternalState(os, "wrappedStream"); DataStreamer streamer = (DataStreamer) Whitebox .getInternalState(dos, "streamer"); @SuppressWarnings("unchecked") LastExceptionInStreamer ex = (LastExceptionInStreamer) Whitebox .getInternalState(streamer, "lastException"); Throwable thrown = (Throwable) Whitebox.getInternalState(ex, "thrown"); Assert.assertNull(thrown); dos.close(); IOException dummy = new IOException("dummy"); ex.set(dummy); try { dos.close(); } catch (IOException e) { Assert.assertEquals(e, dummy); } thrown = (Throwable) Whitebox.getInternalState(ex, "thrown"); Assert.assertNull(thrown); dos.close(); }