Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to manually put data into an InputStream?

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to manually put data into an InputStream?

    Hi all, I am new to programming in regards to I/O, channels, SSH, etc... and I'm finding it quite difficult to find a solution to my problem.
    At the moment I am trying to transform the Shell.java program from the JCraft JSch examples; http://www.jcraft.com/jsch/examples/Shell.java.html

    The way in which I am trying to transform it is by instead of having the character input go into the channel automatically from the keyboard (refer to line 77 in Shell.java), I just want to pro-grammatically insert characters in to the channel at my discretion, so for example I have a string called unixCommand that I want to insert into the channel, and I don't want there to be any other way of inserting into the channel such as the standard input stream, so for example I'd have the statement <insert unixCommand to UNIX box at other side of channel> inserted somewhere after line 100 in Shell.java.

    I was thinking that maybe I have to use some other InputStream object at line 77 when setting the channels input stream instead of System.in, but I am not sure how to do this (but really I'm not sure if I'm even on the right tracks?). I believe all this confusion may be down to a misunderstanding with the general concepts involved with channels and I/O and if so would be very grateful if anyone could help rectify this misunderstanding of mine.

    Thanks
    CuppaJava
    Last edited by CuppaJava; August 23rd, 2014 at 03:56 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 832 Times in 772 Posts
    Blog Entries
    5

    Default Re: How to manually put data into an InputStream?

    The way in which I am trying to transform it is by instead of having the character input go into the channel automatically from the keyboard (refer to line 77 in Shell.java), I just want to pro-grammatically insert characters in to the channel at my discretion, so for example I have a string called unixCommand that I want to insert into the channel, and I don't want there to be any other way of inserting into the channel such as the standard input stream, so for example I'd have the statement <insert unixCommand to UNIX box at other side of channel> inserted somewhere after line 100 in Shell.java.
    Perhaps I misunderstand, but an InputStream is for reading data...if you wish to call a command on the remote ssh box, use the OutputStream to write out to the ssh connection Also, have a look at the Exec.java example for calling exec commands.

    Edit: And please notify of crossposts:

    This thread has been cross posted here:

    http://stackoverflow.com/questions/25466312/how-to-manually-put-data-into-an-inputstream-in-java

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to manually put data into an InputStream?

    Quote Originally Posted by copeg View Post
    Perhaps I misunderstand, but an InputStream is for reading data...if you wish to call a command on the remote ssh box, use the OutputStream to write out to the ssh connection Also, have a look at the Exec.java example for calling exec commands.

    Edit: And please notify of crossposts:

    This thread has been cross posted here:

    http://stackoverflow.com/questions/25466312/how-to-manually-put-data-into-an-inputstream-in-java

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    yeah sorry about that, I'll make sure I go back to all cross posts and post in what worked for me when I find the answer (and stick to 1 forum afterwards), however after looking through more examples of I/O, your reply does make most sense to me at the moment, and as I thought it is a misunderstanding with the fundamental concepts on my part, I don't think you are misunderstanding anything. I'll let you know tomorrow after work how it goes

Similar Threads

  1. Binary File. Extract float data from binary file and put into array
    By cardinal152 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: June 13th, 2012, 07:31 PM
  2. 1 packet delay with inputstream
    By tobi06 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: October 27th, 2011, 04:53 AM
  3. Looping an inputstream
    By Trunk Monkeey in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 25th, 2011, 02:39 PM
  4. [SOLVED] InputStream to File
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: May 2nd, 2011, 01:05 PM
  5. setting cookies manually
    By dotanguy in forum Java Networking
    Replies: 2
    Last Post: July 2nd, 2010, 09:51 AM