• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

pipe, Channel

 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is pipe in java?What is channel? What is difference between channel and streams?

I checked JAVA doc but it is unclear for me.

A channel for reading, writing, mapping, and manipulating a file.


A pipe consists of a pair of channels: A writable sink channel and a readable source channel.





What does mapping mean here?
 
Saloon Keeper
Posts: 15510
363
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Channels and Streams essentially do the same thing, but they are different ways of doing it. They are both sources of data.

A stream is a source/sink where you read or write bytes to or from. Channels work a bit differently. Instead of reading directly from a channel, you pass a ByteBuffer to a Channel, and the Channel will either fill or drain the buffer.
I believe channels are a little bit faster than streams when it comes to reading devices or drives and such, because they are designed to read in bulk. There are also some other methods you can find in FileChannel for fast operations on files.

Personally I prefer using streams most of the time, because writing code for them is a lot less awkward than it is for channels.

File mapping is a nice feature provided by FileChannel. It maps a file to memory, so you can directly edit the file as if you were editing an array of bytes.

A pipe is simply a way of transporting data from one part of your program to another part. Pipes can be implemented with channels, streams, etc.
Let's compare a pipe to, say, a socket connection.
A socket represents the connection between two processes. You can put data in on one side, and it will come out the other side. Pipes work exactly the same way, except they represent a connection between two different parts of the same process, not different processes. For instance, you can have one thread that investigates something, and it will write its findings into one end of a pipe, and another thread will read from the other end of the pipe and process the data.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very Very Good!Thank you!
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Instead of streaming data to a file, a thread can stream it through a pipe to another thread. The first thread writes to the
pipe, and the second thread reads from the pipe. A pipe is neither a file nor a network connection, but a structure in memory that holds the data that is written until it is read.



I search forum about pipe, and find that. As I see,Pipe is used for connection between tow programming language in order to transport data, Like JAVA and C, May you explain baout the mechanism of this transportation?

I also seached in internet and see pipe is used in netwrok programming,Is it the pipe use in network programming is same pipe used in thread communication?
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I suppose that's one of the applications for a pipe.

Let's say you have a hardware device that contains sensors (for instance, for light, temperature, acceleration, etc). Its driver may be written in a language like C. It might be set up in a way that it sends all its sensor data through a pipe. Your program that uses the hardware might then be written in Java, which reads the data from the pipe and processes it.

Regarding network programming, I'm not sure what they are referring to. It sounds like a simple socket connection, which in a broad abstract sense you could understand as a pipe, but I prefer to use the word pipe for a connection within the same process.

Do you have a link to where you read these things?
 
abalfazl hossein
Ranch Hand
Posts: 635
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May someone answer me please?
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The topics you linked to refer to a special mechanism most operating systems provide. This mechanism "pipes" the standard output of one process to the standard input of another process. In most operating systems this is done using the pipe symbol: |

Here is an example in Unix:
If I'm not mistaken, anything you write to System.out in FirstMain, will be available to System.in in SecondMain.
 
reply
    Bookmark Topic Watch Topic
  • New Topic