This repository has been archived by the owner on Jul 24, 2021. It is now read-only.
forked from rmichela/Bukkit-SSHD
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This should actually fix rmichela#10
- Loading branch information
Showing
5 changed files
with
31 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 26 additions & 16 deletions
42
src/main/java/com/ryanmichela/sshd/FlushyOutputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,59 @@ | ||
package com.ryanmichela.sshd; | ||
|
||
import org.apache.sshd.common.SshException; | ||
import org.apache.sshd.common.channel.exception.SshChannelClosedException; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.math.BigInteger; | ||
|
||
/** | ||
* Copyright 2013 Ryan Michela | ||
*/ | ||
public class FlushyOutputStream extends OutputStream { | ||
public class FlushyOutputStream extends OutputStream | ||
{ | ||
|
||
private OutputStream base; | ||
private boolean isClosed = false; | ||
|
||
public FlushyOutputStream(OutputStream base) { | ||
public FlushyOutputStream(OutputStream base) | ||
{ | ||
this.base = base; | ||
} | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
if (isClosed) return; | ||
base.write(b); | ||
base.flush(); | ||
public void write(int b) throws IOException | ||
{ | ||
this.write(BigInteger.valueOf(b).toByteArray()); | ||
} | ||
|
||
@Override | ||
public void write(byte[] b) throws IOException { | ||
if (isClosed) return; | ||
base.write(b); | ||
base.flush(); | ||
public void write(byte[] b) throws IOException | ||
{ | ||
this.write(b, 0, b.length); | ||
} | ||
|
||
@Override | ||
public void write(byte[] b, int off, int len) throws IOException { | ||
if (isClosed) return; | ||
try { | ||
public void write(byte[] b, int off, int len) throws IOException | ||
{ | ||
if (isClosed) | ||
return; | ||
|
||
try | ||
{ | ||
base.write(b, off, len); | ||
base.flush(); | ||
} catch (SshException e) { | ||
if (!e.getMessage().contains("channel already closed")) throw e; | ||
} | ||
catch (SshChannelClosedException e) | ||
{ | ||
// ignored. | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
public void close() throws IOException | ||
{ | ||
isClosed = true; | ||
base.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters