PaCkAgE DaTaStReAm input/output stream utilities

I am trying to read/write Solaris installable package streams and I was wondering if someone had already invented this wheel. Since I cannot seem to find ANY documentation on the internet about the file format (and, more importantly, the header encoding) for the items in these files I was hoping someone here would have information about this.
And, no, I am not able to exec() mkpkg, pkgtrans, etc as I may not be running on a Solaris machine.

Wow. That was easy. The Sun package datastream format is simply two cpio files concatenated together on a 512 byte boundary. Still trying to figure out the main package header (which is also 512 bytes) and contains the "PaCkAgE DaTaStReAm" tag and the name of the package itself followed by two numbers, a '1', which hold no special meaning yet and the number of 512-byte blocks occupied by the installed package). So far my ant task is shaping up nicely and I'll be able to create Solaris packages via build.xml :D

Similar Messages

  • Socket input / output stream

    Does anyone know if the input / output streams returned by getInputStream() / getOutputStream() in java.net.Socket are buffered by default?

    y they are buffered, but to use the buffer, you have to use available() and read(byte[] buf ...

  • Buffered input/output stream

    How the buffereing is done in buffered input/output streams?
    From the API doc I got to know that they use internal buffer to store bytes before they can be read or written. But i found that File input/output stream also have methods like read(byte[]) or write(byte[]). So what is extra in buffered input/ouput streams? Does the phrase "buffered" suggests that bytes can be read from an array or be written to an array? Am i thinking the right way?

    How the buffereing is done in buffered input/output
    streams?
    From the API doc I got to know that they use internal
    buffer to store bytes before they can be read or
    written. But i found that File input/output stream
    also have methods like read(byte[]) or write(byte[]).Thouse are your buffer, not the streams'.
    So what is extra in buffered input/ouput streams?
    Does the phrase "buffered" suggests that bytes can be
    read from an array or be written to an array? Am i
    thinking the right way?No. It means that the stream either prefetches some data even if it's not requested yet, or that it withholds data that it's supposed to write until it's flushed or gets a larger chunk.

  • Object input/output stream

    Hi, i'm currently doing a software enginnering project at university. I need to understand how to save and read from files.
    I've been told to look at object input/output stream, which I have, but I can't get my head around what's written in the books. Does anyone know where i can find a good tutorial on this subject?
    thanks
    AK

    I like the tutorial on this site because it tells you what to use for what you're doing (click on Using the Streams). Hope it helps!
    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • Get multiple Input/Output Stream from same socket ?

    For a better express of my problem i will put my test example
    I have those 4 classes
    package test;
    import...
    public class ReaderExecutor extends Thread{
            private InputStream in = null;
            private static int defaultID = 0;
            private int ID = getID();
            public ReaderExecutor(InputStream in){
                this.in = in;
            public void run(){
                try {
                    int c ;
                    while ((c=in.read())!=-1)
                        System.out.println("ReaderThread " + this.ID + ":" + c);
                catch (IOException e) {
                    System.out.println("ReaderThread "+this.ID+" stopped !");
            private static int getID(){
                return defaultID++;
    package test;
    import...
    public class WriterExecuter extends Thread{
        OutputStream out = null;
        private static boolean odd = true;
        private boolean isOdd ;
        public WriterExecuter(OutputStream out) {
            this.out = out;
            isOdd = odd;
            odd = !odd;
        public void run(){
            try{
                for (int i = isOdd?1:2;i<10;i+=2){
                    System.err.println(i);
                    out.write(i);
            }catch(Exception e){
                System.out.println("WriterThread stopped !");
    package test;
    import...
    public class Main { 
        public Main() {
        public static void main(String[] args) throws Exception {
            try{
                ServerSocket ss = new ServerSocket(9090);
                System.out.println("Ascult ... ");
                Socket client = ss.accept();
                new ReaderExecutor(client.getInputStream()).start();
                //Thread.sleep(2000);
                new ReaderExecutor(client.getInputStream()).start();
            }catch (Exception e){
                e.printStackTrace();
    package test;
    import...
    public class Main1 {
        public Main1() {
        public static void main(String[] args) {
            try{
                Socket s = new Socket("localhost",9090);
                WriterExecuter t= null ;
                t = new WriterExecuter(s.getOutputStream());
                t.start();
                t = new WriterExecuter(s.getOutputStream());
                t.start();
            }catch(Exception e){
                e.printStackTrace();
    }Now if i run successive Main , Main1 i get this output
    Ascult ...
    ReaderThread 0:0
    ReaderThread 1:0
    ReaderThread 0:0
    ReaderThread 1:0
    ReaderThread 0:0
    ReaderThread 1:0
    ReaderThread 0:0
    ReaderThread 1:0
    ReaderThread 0:0
    ReaderThread 0 stopped !
    ReaderThread 1 stopped !The question is can i get other Input/Output individual streams with a separate logic functionality from the same socket?
    From this example it seems i can't :(
    Thx
    Alex

    For what you are trying to do the simplest solution is to have one socket per "stream" that is the way they are designed to be used.
    However, you can multiplex multiple stream over a single socket, but you have do the coding yourself or use a solution which does this for you e.g. JMS. (There is no support at the socket level for this)

  • Questions about input/output streams

    In the following tutorial:
    http://chortle.ccsu.ctstateu.edu/CS151/Notes/chap85/ch85_10.html
    It mentions that some methods, such as write(), writeByte(), writeBytes(), and writeChar(), return the low eight bits of the argument to the output stream. I am a little unsure of what exactly that means, might somebody be able to clarify for me?
    In addition, I've been encountering the flush() method in some of the byte- and character-streaming objects that deal with buffers. What exactly is the flush() method's purpose, and when might it be used? Thank you.

    flush pushes the data out of the buffer. the write methods write to the buffer, when the buffer is full, it flushes itself (usually), or it could block the write methods (in theory). flush just lets you make sure that it's flushed.
    I'm not sure there's any reason to worry about high and low bytes in Java most of the time. I suppose, like anything, there's times you need to, but I can't think of any offhand.

  • Input/output stream coupler (like a pipe, but reversed)

    I could write my own class but, for standardization purposes, I was wondering if there is anything in the Java API that does this:
    I have a Reader and a Writer and I want to connect them so that as soon as data is available from the Reader, it is written directly to the Writer.
    Reader>===>Writer
    as opposed to a pipe which looks loke
    Writer>===>Reader
    Is there such a class?

    I don't know of such a class, but you have the same API docs available to you as the rest of us. If you don't see it in java.io or java.nio or java.nio(.*), then it's not in the core API. At that point, I'd check sourceforge, jakarta, mindprod. After that, I might be inclined to post here, but I'd probably just say screw it and write my own.

  • File being erased during input output stream

    I am trying to send a .txt to an ftp server. The application will send the file but it is empty on the server end AND my original! The file is still there but is 0 kb with all data deleted. I cant seem to figure out what I'm doing wrong. Any ideas?
    try{     
    URL url = new URL("ftp://username:[email protected]/file.txt;type=i");
        URLConnection con = url.openConnection();
        BufferedInputStream in =
        new BufferedInputStream(con.getInputStream());
        FileOutputStream out = new FileOutputStream("file.txt");
    int i = 0;
    byte[] bytesIn = new byte[1024];
    while ((i = in.read(bytesIn)) >= 0) {
         out.write(bytesIn, 0, i);
    out.close();
    in.close();
         catch(Exception nio){System.out.println(nio);}

    I am trying to send a .txt to an ftp server.There's the problem right there. The code you posted copies data FROM the server TO your local system.

  • MultiThreading with Input and Output Streams

    Hi,
    I have a problem and I think it's because I'm not coding correctly. Please help me if you can understand what I'm doing wrong.
    I have a server that spawns a separate thread to go off and collect data from a serial port. It also waits to accept connections from any client and if a connection is made it will send that data to the clients connected.
    There is data constantly coming in through the serial port. It is output through a DataOutputStream so when the thread is created in the server, I pipe it into a DataInputStream. I do does because I want the server to then read in the data from the inputstream and then send it out to all my clients.
    So far, the way I have it set up seems to do this. But my problem occurs when I try to close a client connection. Instead of removing the socket connection it gives me an error that it can't send data to the client, but it shouldn't be sending data to the client because I just closed it. I realize this is probably because I'm still constantly receiving data from my inputstream and the connection was closed so it can't send that data to the client. I know I need to either close the stream or close my socket but I don't know where this needs to be done. I'm stuck on the correct way to fix this.
    My second problem is the initial connection made to receive data from the inputstream. This is probably because I'm not very familiar with how input/output streams work. But instead of just sending the client the current data being received in real time, it'll send all the data that's buffered in the inputstream. I don't want all the data that's been collecting to go to that first client. I only want the recent data that is coming through while the client is connected. Does this make sense? Because after I make a second client connection I don't have this problem because the InputStream is no longer buffered up. Should I be using something else besides the DataInputStream?
    I feel like I'm going about this the wrong way. Please advise. I'm shy about showing the code but I've included the bulk of it here in hopes that someone will see what I'm doing wrong. The only part that's left out is the thread that reads from the serial port. I don't seem to have any problems with that thread.
    Thanks,
    kim
    ===
    import java.io.*;
    import java.net.*;
    import javax.comm.*;
    import java.util.*;
    // DataServer waits for a client connection
    class DataServer
         static final int PORT = 7;
         // The ServerSocket to use for accepting new connections
         private ServerSocket ss;
         // A mapping from sockets to DataOutputStreams. This will
         // help us avoid from having to create a DataOutputStream each time
         // we want to write to a stream.
         private Hashtable outputStreams = new Hashtable();
         // The inputstream that will receive serial port data through a
         // piped inputstream
         public DataInputStream datalogger;
         // Constructor and while-accept loop all in one.
         public DataServer() throws IOException
              try {
                   // Creating pipe to convert the outputstream from the
                   // RS232 Thread to an inputstream for the server to read
                   PipedOutputStream pout = new PipedOutputStream();
                   PipedInputStream pin = new PipedInputStream(pout);
                   // The inputstream that will receive data from the RS232Thread
                   datalogger = new DataInputStream(pin);
                   // Spawn the thread that will read data through from
                   // the TINI serial port
                   new RS232Thread( pout ).start();
                   // Begin listening for connections and send data
                   listen();
              } catch (IOException ioe) {
                   System.out.println("Error >> DataServer::DataServer()");
                   System.out.println(ioe.getMessage());
                   ioe.printStackTrace();
              } finally {
                   try     {
                        System.out.println( "Closing >> DataServer::DataServer()" );
                        datalogger.close();
                   } catch (IOException i ) {
                        System.out.println( "Error2 >> DataServer::DataServer()" );
                        System.out.println(i); }
         private void listen() throws IOException
              // Create the ServerSocket
              ss = new ServerSocket( PORT );
              // Inform that the server is ready to go
              System.out.println( "Listening on " + ss );
              // Keep accepting connections forever
              while (true) {
                   // Grab the next incoming connection
                   Socket s = ss.accept();
                   // Inform that connection is made
                   System.out.println( "Connection from " + s );
                   // Create a DataOutputStream for writing data to the
                   // other side
                   DataOutputStream dout = new DataOutputStream( s.getOutputStream() );
                   // Save this stream so we don't need to make it again
                   outputStreams.put( s, dout );
                   // Create a new thread for this connection, and then foret
                   // about it
                   new ServerThread( this, s );
         // Get an enumeration of all the OutputStreams, one for each client
         // connected to the server
         Enumeration getOutputStreams() {
              return outputStreams.elements();
         // Send a message to all clients (utility routine)
         void sendToAll( byte[] b ) {
              // synchronize on this because another thread might be
              // calling removeConnection() and this would screw things up
              // while it walks through the list
              synchronized( outputStreams ) {
                   // For each client...
                   for (Enumeration e = getOutputStreams(); e.hasMoreElements();) {
                        // ... get the output stream ...
                        DataOutputStream dout = (DataOutputStream)e.nextElement();
                        // ... and send the message
                        try {          
                             dout.write( b );
                        } catch(IOException ie) {                     
                             System.out.println( "Error >> ServerThread::sendToAll()" );
                             System.out.println( ie );
         // remove a socket, and it's corresponding output stream, from the
         // list. This is usually called by a connection thread that has
         // discovered that the connection to the client is dead.
         void removeConnection( Socket s ) {
              // Synchronize so it doesn't mess up sendToAll() while it walks
              // down the list of all output streams
              synchronized( outputStreams ) {
                   // Inform about removal
                   System.out.println( "Removing connection to " + s );
                   // Remove if from our hastable/list
                   outputStreams.remove( s );
                   // Make sure it's closed
                   try {
                        s.close();
                   } catch( IOException ie ) {
                        System.out.println( "Error closing " + s );
                        ie.printStackTrace();
         // main - Opens a server socket and spins off a new thread each time
         // a new client connection is accepted on this socket.
         public static void main(String[] args) throws Exception
              System.out.println("Starting DataServer version 1.0 ...");
              try     
                   new DataServer();
              catch (IOException ioe)
                   System.out.println( "Error >> DataServer::main()" );
                   System.out.println(ioe.getMessage());
                   ioe.printStackTrace();
    class ServerThread extends Thread
         //The Server that spawned this thread
         private DataServer server;
         // The Socket connected to the client
         private Socket socket;
         //Constructor
         public ServerThread( DataServer server, Socket socket )
              // save the parameters
              this.server = server;
              this.socket = socket;
              // Start up the thread
              start();
         // This runs in a separate thread when start() is called in the
         // constructor
         public void run() {
              try {
                   // The inputstream receiving data from the global inputstream
                   // that is piped to the RS232 Thread
                   // ???? is this where i'm messing up ???
                   DataInputStream in = new DataInputStream( server.datalogger );
                   int num = 0;
                   byte[] d = new byte[1];
                   // read from the inputstream over and over, forever ...
                   while( ( num = in.read(d) ) > 0 ) {
                        // ... and have the server send it to all clients
                        server.sendToAll( d );               
              } catch (IOException ioe) {
                   System.out.println( "Error >> ServerThread::run()" );
                   System.out.println(ioe.getMessage());
                   ioe.printStackTrace();
              } finally {
                   // The connection is closed for one reason or another,
                   // so have the server dealing with it
                   System.out.println( "Closing" );
                   server.removeConnection( socket );

    A couple of things to note...
    First, you are looping infinitely in your server's constructor. Since the constructor is never completing, your server object is never completely constructed - this may cause indeterminate behaviour when you pass a reference to the server to another thread.
    Second, I would recommend fixing your issues by modifying your design somewhat. The design I would recommend (read: The design I would use) is:
    A server object, with a public listen method. The constructor spawns a thread to constantly read from the serial port and forward the data read back to the server, via a multicast (sendToAll) method.
    The listen method sets up a server socket to accept connections, and in a loop opens client sockets and stores them in a set.
    The multicast method iterates through the list of open client sockets, and for each in turn confirms that it is still open. If open, send the data down the socket's output stream; if closed, remove the socket from the set.
    Note that this design includes only two threads - the main thread listens for and accepts new socket connections, while the extra thread collects data from the serial port, multicasts it to all of the open sockets, and removes all of the closed sockets. If you require to perform any other communication with the sockets, it may be necessary to create a thread for those sockets, to facilitate reading from their input streams, but in the given design, this is not necessary.
    I hope this helps,
    -Troy

  • Sharing an output stream from more than 1 thread.

    I have a problem, an ObjectOutputStream is giving me a nullpointerexception.
    I have a thread which connects to a server application and uses object input/output streams to communicate. This thread will deal with any incoming requests from the server concurrently from the main program. I presumed you could use the same Socket connection that was created in this thread to send objects from other threads (for example the main thread) but I think I presumed wrong.
    This is part of the class which runs as a separate thread:
        public void connect()
            try
                mainSocket = new Socket(hostName, hostPort);
                in = new ObjectInputStream(mainSocket.getInputStream());
                out = new ObjectOutputStream(mainSocket.getOutputStream());
            catch(UnknownHostException e)
                System.out.println(e.getMessage());
            catch(IOException e)
                System.out.println(e.getMessage());
        public void run()
            connect();
            while(true)
             // (Not complete)
        public boolean verifyEmployeeName(String employeeName)
            boolean answer = false;
            try
                out.writeObject(Server.protocol.VERIFY_EMPLOYEE);
                out.writeObject(employeeName);
                answer = in.readBoolean();
            catch(IOException e)
            return answer;
        }The verifyEmployeeName() method is called externally from the main thread and generates the IOException at out.writeObject(Server.protocol.VERIFY_EMPLOYEE); (or the first point at which the socket is used). Anyway my question is; do you have to create a new socket for each thread (bear in mind I haven't yet put in synchronization features) or is this nothing to do with that?
    Very grateful for any help you have to offer.

    alex.p wrote:
    Anyway my question is; do you have to create a new socket for each thread (bear in mind I haven't yet put in synchronization features) Not necessarily. But you'll have to sequentialise the communication.
    Create a communication thread. Give it the control over the socket. Have it expose a BlockingQueue that takes some form of "tasks". As a thread, that communicator polls its queue, and executes the tasks. Other threads post their tasks on the queue and wait until they're completed. Look for clues in the java.util.concurrent package.

  • Facing error in creating ObjectInput/output stream socket

    hi I am Jatandar and i am implemeint client server program which will be using object Input/Output stream to pass data through sockets . The problem is the i m getting error when the cleint connects to the server here is the server and client code , YOur help will be appreciated
    Inventory class with serializable has been implemented
    public class Client
    public static void main( String [] args )//throws IOException
    Inventory invt[];
    try
    Socket serv = new Socket( "localhost", 8000 );
    // connect to server at port 8000
              ObjectInputStream ois ;     
    ois= new ObjectInputStream(serv.getInputStream());
    invt=(Inventory[]) ois.readObject() ;
    System.out.println(invt[0]);
    catch(IOException e )
    System.out.println(" no server Found \n");
    catch(Exception e)
    System.out.println(e);
    public class A3Server
         public static void main(String arg[] ) throws IOException
              //create a Server Socet
              ServerSocket ss= new ServerSocket(8000) ;
              ObjectOutputStream oos;
              //create a clent Socker that will listen for connection
              //listen for the connection from client
              BufferedReader br=null;
              FileReader fr=null;
              LinkedList ll=new LinkedList();
              StringTokenizer stkr;
              int i=0;
              Inventory inv=new Inventory();
              Inventory invt[];
              String t[]=new String[5];
              boolean choice=true;
              String temp="",temp2;
    // i am reading a text which contain data
    //that data is stored in invt []
    //that array is transfered to clien t when it is connected
         Socket toClient= ss.accept();
    oos = new ObjectOutputStream(toClient.getOutputStream());
    oos.writeObject(invt );
         oos.close();     
              }// end of main fucniton
         }//end of Server class
    DETAIL OF ERROR
    error in natived socket write method

    hi I am Jatandar and i am implemeint client server program which will be using object Input/Output stream to pass data through sockets . The problem is the i m getting error when the cleint connects to the server here is the server and client code , YOur help will be appreciated
    Inventory class with serializable has been implemented
    public class Client
    public static void main( String [] args )//throws IOException
    Inventory invt[];
    try
    Socket serv = new Socket( "localhost", 8000 );
    // connect to server at port 8000
              ObjectInputStream ois ;     
    ois= new ObjectInputStream(serv.getInputStream());
    invt=(Inventory[]) ois.readObject() ;
    System.out.println(invt[0]);
    catch(IOException e )
    System.out.println(" no server Found \n");
    catch(Exception e)
    System.out.println(e);
    public class A3Server
         public static void main(String arg[] ) throws IOException
              //create a Server Socet
              ServerSocket ss= new ServerSocket(8000) ;
              ObjectOutputStream oos;
              //create a clent Socker that will listen for connection
              //listen for the connection from client
              BufferedReader br=null;
              FileReader fr=null;
              LinkedList ll=new LinkedList();
              StringTokenizer stkr;
              int i=0;
              Inventory inv=new Inventory();
              Inventory invt[];
              String t[]=new String[5];
              boolean choice=true;
              String temp="",temp2;
    // i am reading a text which contain data
    //that data is stored in invt []
    //that array is transfered to clien t when it is connected
         Socket toClient= ss.accept();
    oos = new ObjectOutputStream(toClient.getOutputStream());
    oos.writeObject(invt );
         oos.close();     
              }// end of main fucniton
         }//end of Server class
    DETAIL OF ERROR
    error in natived socket write method

  • Using two ports or Using two Input / Outputs

    I'm explaining my project. It s almost done. I send message and data to server and it is stored in server. From the begining I'm using
    BufferedReader - PrintWriterAnd I cannot send files because they are binary. I have to use
    BufferedInputStream - BufferedOutputStreamI cannot change my input / output. So I found two solutions:
    1) Connecting from another port with another socket. -> Using this it blames the ports. I cannot transfer anything from my first port.
    2) Using another input / output streams from the same port. -> I didn't tried it . Does anyone tried this. Is it possible to do this.
    That's the end of my project. I will give the name of project who gives me a good answer :D
    Best Regards, Bulent.

    I cannot change my input / output. Why not?
    So I found two solutions:
    1) Connecting from another port with another
    er socket. -> Using this it blames the ports. I
    cannot transfer anything from my first port.Huh? Unless the server stops you, there is nothing in sockets that prevents you, as a client, from connecting to the server twice.
    2) Using another input / output streams from the
    he same port. -> I didn't tried it . Does anyone
    tried this. Is it possible to do this. Nothing stops you from using an InputStream to create two different buffered solutions.
    I wouldn't even attempt this myself. It would create a very fragile application. But you could try it. You would need to carefully control when the two connections were used and in particular when they were closed. You could do this by wrapping both in a class.

  • Do I need to study Inut/Output streams for the CX-310-035 exams

    Hi,
    I am a little confused.
    I have the Java 2 Certification Study Guid (Third Edition.
    In the objectives section, it says nothing of java.io (Input/OutPut streams right?), yet in the guide itself, it has a whole chapter on this.
    So what is the dea?Am I required to sudy this for the Sun Certified Programmer for the Java 2 Platform 1.4 (CX-310-035), or do I totally leave it out.
    Thanks all

    I find this to a bit stupid. I found reading the I/O chapter to be informative. I often did I/O things a bit blindly before preparing and am now better equipped to choose the correct classes when programming. Further, look how many questions we see in here of the ilk, "How do read from a file and then tokenize the bits and then do some processing and then write them back out using Unicode cuneiform"?

  • Input / Output Object Stream

    Hello
    I'm using Input / Output Object Stream to transfer an object between a client / server utilities.
    I create an object and give it a state, then used the OutputObjectStream.
    After sending the object for the first time (and recieving it in the InputObjectStream), I change the state of the object and send it again using the same output stream.
    On the recieving side I got the "Old" object, i.e. an object with the Old State.
    any idea ???
    Oded

    The Object Stream keeps track of references to objects and only sends an object once.
    This is to allow you to send objects which contain circular references.
    The may around this is to call reset() on the ObjectOutputStream. This causes it to forget all refrences (And the ObjectInputStream)
    You have to do this anyway otherwise the ObejctOutputStream will remember more and more objects until you run out of memory!

  • Java Input and Output streams

    I have maybe simple question, but I can`t really understand how to figure out this problem.
    I have 2 applications(one on mobile phone J2ME, one on computer J2SE). They commuinicate with Input and Output Streams. Everything is ok, but all communication is in sequence, for example,
    from mobile phone:
    out.writeUTF("GETIMAGE")
    getImage();
    form computer:
    reply = in.readUTF();
    if(reply.equals("GETIMAGE")) sendimage()
    But I need to include one simple thing in my applications - when phone rings there is function in MIDlet - pauseApp() and i need to send some signal to Computer when it happens. But how can i catch this signal in J2SE, because mayble phone rings when computer is sending byte array? and then suddnely it receives command "RINGING"....?
    Please explain how to correcly solve such problem?
    Thanks,
    Ervins

    Eh?
    TCP/IP is not a multiplexed protocol. And why would you need threads or polling to decipher a record-oriented input stream?
    Just send your images in packets with a type byte (1=command, 2=image, &c) and a packet length word. At the receiver:
    int type = dataInputStream.read();
    int length = dataInputStream.readInt();
    byte[] buffer = new byte[length];
    int count, read = 0;
    while ((count = dataInputStream.read(buffer,count,buffer.length)) > 0)
    read += count;
    // At this point we either have:
    // type == -1 || count = -1 => EOF
    // or count > 0, type >= 0, and buffer contains the entire packet.
    switch (type)
    case -1:
    // EOF, not shown
    break;
    case COMMAND: // assuming a manifest constant somewhere
    // process incoming command
    break;
    case IMAGE:
    // process or continue to process incoming image
    break;
    }No threads, no polling, and nuthin' up my sleeve.
    Modulo bugs.

Maybe you are looking for