Skip to content

Commit

Permalink
ssh: update DirectCommand to use SshOutputStream
Browse files Browse the repository at this point in the history
Motivation:
as DirectCommand prints the result of the commands to a console it
should follow the same rules as AnsiTerminalCommand output (\r\n)

Modification:
Pull SshOutputStream out of AnsiTerminalCommand and update DirectCommand
to use by when printing the output.

Result:
Correct direct command output if some terminal configurations.

Acked-by: Lea Morschel
Acked-by: Paul Millar
Acked-by: Dmitry Litvintsev
Target: master
Require-book: no
Require-notes: no
  • Loading branch information
kofemann committed Jun 3, 2021
1 parent ddd6c88 commit a705b0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
Expand Down Expand Up @@ -292,23 +291,6 @@ public int getWidth() {
}
}

private static class SshOutputStream extends FilterOutputStream
{
public SshOutputStream(OutputStream out) {
super(out);
}

@Override
public void write(int c) throws IOException {
if (c == '\n') {
super.write(0xa);
super.write(0xd);
} else {
super.write(c);
}
}
}

private class Pipe implements Runnable
{
public static final int CTRL_C = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void destroy() {

@Override
public void setErrorStream(OutputStream err) {
errorWriter = new PrintWriter(err);
errorWriter = new PrintWriter(new SshOutputStream(err));
}

@Override
Expand All @@ -149,7 +149,7 @@ public void setInputStream(InputStream in) {

@Override
public void setOutputStream(OutputStream out) {
outWriter = new PrintWriter(out);
outWriter = new PrintWriter(new SshOutputStream(out));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.dcache.services.ssh2;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

class SshOutputStream extends FilterOutputStream {
public SshOutputStream(OutputStream out) {
super(out);
}

@Override
public void write(int c) throws IOException {
if (c == '\n') {
super.write(0xa);
super.write(0xd);
} else {
super.write(c);
}
}
}

0 comments on commit a705b0a

Please sign in to comment.