Object stream and byte array conversion

Hello everyone,
I am wondeirng how to convert an ObjectInputStream to a byte array, then convert the array back to ObjectInputStream -- should I convert the array back to ObjectOutputStream other than ObjectInputStream?
Any sample codes?
thanks in advance,
George

Isn't it the other way around? You can't do this directly:
ObjectInputStream ois = ...;
ByteArrayInputStream bais = new ByteArrayInputStream(ois);(but you can do it indirectly), but you can do this:
ByteArrayInputStream bais = ...;
ObjectInputStream ois = new ObjectInputStream(bais);

Similar Messages

  • How do i convert an image object to a byte array ?

    Hi
    how do i convert an image object into a byte array
    early reply apperciated

    Oh sorry my method and the other method need to have the pixels from the Image passed to them which you get my using pixelgrabber:
    //create width and height variables from image
              int w = img.getWidth(this);
              int h = img.getHeight(this);
              //retrive picture from image
              int[] pix = new int[w * h];
              PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
              try{ pg.grabPixels();
              } catch (InterruptedException ioe) {
                   System.err.println("Interrupted");
              if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
              System.err.println("image fetch aborted or errored");
              }

  • Confusion regarding Binary data and byte arrays

    HI guys,
    I have a question...i am going to send some binary data...the format of that data is that first two bytes is the lenght of the data and then follows that data. Here i have one confusion. e.g. i want to say that the lenght of my data is 1000 bytes. How do i do it.
    coz if i do something like this.
    int k = 1000;//the length of my data
    String binaryString = Integer.toBinaryString(k);
    byte[] binaryData = binaryString.getBytes();
    and then if i say binaryData.lenght, i see a lenght of 10, as the binary string which
    is generated is -> 1111101000. i guess its obivious as this byte array is nothing but perhaps a character array with each character occupying one thread...so what exactly is the difference between byte array and binary data. and in the above said condition how do i send the binary data?
    Also adding to my confusion is the fact that i have a file which contains binary data, but that data is not 10010101 type of data...its just some absurd characters. How do we explain this.
    i would be highly grateful if you could explain me the solution to this problem.
    I am not getting as to how to go about it.
    its urgent..pls help...

    one sec..actually i dont want to 'read' the two bytes. That i know how to do? but The thing is that i want to write a binary stream. right? so in that the first two bytes should be the size of the data, followed by the data itself. So i want to write the first two bytes, which should contain the size of data (as a matter of fact i have that binary data in a byte array). But my question is , that if i say the size of data is 1000 (bytes , since, as i said i am gettting the data as a byte array), how do i write this in my binary stream as 1000 in this case would be an int. right? which is four bytes. So essentially that byte array (which contains binary data) i have to forward to somewhere, say X , but X reads binary data in the following way...it expects the first two bytes to give him info regarding the size of the data to follow and then it starts reading the data from the third byte onwards till the size of the data (which it got by reading first two bytes)...i hope i could communicate my confusion better this time

  • ImageIcon and byte array

    ImageIcon II = new ImageIcon( myUrl );
    Will give me an ImageIcon based upon the URL given.
    I know an alternate constructor ImageIcon II = new ImageIcon( myByteArray );
    Whereby one can get an ImageIcon based on a given ByteArray.
    Is there any way to go the other way?
    I'd like to get a byte array from a given ImageIcon.
    Any suggestions?

    The reason for the post is that I'd like to store a bunch of images (I don't know in advance how big this bunch is going to be so I'm putting the collection in an ArrayList) in one file. I can do this with a ArrayList of byte-arrays or with a Vector/ArrayList of ImageIcons.
    Will an ArrayList of byte arrays containing byte-arrays differ much in size with a ArrayList of ImageIcons? The Serilaized Form section of the API does not give me very useful information in this regard. I'm thinking putting byte arrays in the ArrayList will save me some space, but if this savings isn't very much I'm going to go ahaead and stroe a Vector/ArrayList of ImageIcons.

  • How to change the image into byte and byte array into image

    now i am developing one project. i want change the image into byte array and then byte array into image.

    FileInputStream is = new FileInputStream(file);
    byte[] result = IOUtils.toByteArray(is);
    with apache common IO lib

  • Is it possible to create a PDDoc object directly from the content stream (or byte array) in memory instead from a physical file?

    I want to read a pdf that has been saved to the database and if it has been signed display the signer's name and the sign date to the user.  If the file is first saved to a physical location I can do this with the SDK/ JSObject it there anyway I can do this without a physical file?  This is part of a C# application.

    OK.
    However, if you are using the SDK, then you are using Acrobat – it just may be doing all it’s work hidden.
    So the plugin that you have installed in Acrobat is therefore also hidden, doing its work behind the scenes, on command of your application.

  • How to test if object is a byte array?

    hi,
    does anyone know if there is a way for getting the Class constant for a byte[] that can be used with instanceof? like in below?
    for the primitive boolean type there is Boolean.TYPE, which gives a Class object for a primtive type? but a boolean is not an object? I don't know if this is related to the above though??
    thanks,
    asjf
    public class isByteArray
         public static void main(String [] arg) throws Exception {
              Object [] os = new Object [] { new byte [10],
                   new java.awt.datatransfer.UnsupportedFlavorException(new java.awt.datatransfer.DataFlavor())
              for(int i=0; i<os.length; i++)
                   System.out.println(os.getClass().getName()+" is byte [] ? "+isByteArray(os[i]));
         static byte [] b = new byte [0];
         public static boolean isByteArray(Object o) {
              return b.getClass().isInstance(o);
         /* would like */
         public static boolean isByteArray(Object o) {
              return o instanceof (byte[]).class;

    thanks..
    (I'd been trying
    o instanceof (byte[])
    and lots of other variations..)

  • Problems with Data Objects, streams, and openDoc

    When I try to use this.openDataObject("myObject") in Acrobat 8, I get
    NotAllowedError: Security settings prevent access to this property or method.
    Doc.openDataObject:1:Console
    I have checked that the attachment type is allowed in the registry (and it is by default since the attachment is PDF), so is there a setting that can prohibit JavaScript from opening attachments?  If so, can I change this setting somewhere?
    I have discovered that while the above issue needs to be resolved, it is only part of the problem.  I am trying to read in a PDF file using Net.HTTP.request, convert the response using stringFromStream, then feed the response to createDataObject.  The result is not a valid PDF file.  Is this process possible or am I going about this the wrong way?  I have also tried app.openDoc, but since the PDF is located on our intranet https://someserver.com/doc.pdf I get a security error.  Using only folder level JavaScript, is it possible to open a remote file from a web server, evaluate its Doc object (fields, etc), then save the file back out to the local file system?
    Thanks,
    Scott
    Message was edited by: AcroBishop

    I have hundreds of Acrobat PDF forms out on the company web server.  There is a web service that produces an xml feed which lists all of the documents hosted on that server.  I read in the XML and query it to return the URL of a desired PDF.  What I need is a way to import the Doc object of that PDF so that I can enumerate over all of the fields and populate a listbox in the current document with those field names.  If I could then save the imported PDF to a local folder, well... that would just be icing on the cake.  The way I have been trying to go about this is to feed the URL to Net.HTTP.request which should (in theory) return the PDF as a stream object.  I run util.stringFromStream on that object because I want to feed it to createDataObject which requires a string to act upon.  My problems at this point in the operation are:
    1. I don't think this creates a valid PDF document object and I'm not sure if it should or if I am doing something wrong.  Though I am passing the correct MIME type to the createDataObject (application/pdf)
    2. regardless of the type or validity of the attachment, I get the error message that I mentioned in my original post which leads me to believe that somehow this company has disabled opening attachments via JavaScript.  If that is the case I need to know how to change that configuration.

  • Class Object into Byte Array

    Is there a way to copy a class object into a byte array? If so, how?

    hi check out
    http://forum.java.sun.com/thread.jspa?threadID=562268&
    messageID=2766098This does not work in j2me. WriteObject does not exist, and there are no serialsation interfaces in j2me. So you'll have to do that on your own.
    look here: http://java.sun.com/developer/J2METechTips/2002/tt0226.html

  • Java.sql.SQLException: Byte array not long enough

    using thin jdbc returned this exception seems to be connected to the length of the statment:
    ////////create a prepared statement////////
    preUpdateStatement = dbConnection.prepareStatement(updateStatement.toString());
    // build data output stream on byte array output stream
    ByteArrayOutputStream byte_os = new ByteArrayOutputStream();
    DataOutputStream data_os = new DataOutputStream(byte_os);
    // write chars to data output stream
    data_os.writeChars(((Element)m_values_vector.elementAt(i)).m_value);
    // create input stream and pass it to prepared statement
    ByteArrayInputStream byte_is = new ByteArrayInputStream(byte_os.toByteArray());
    preStatement.setUnicodeStream(i+1, byte_is, byte_os.toByteArray().length);
    // execute
    preUpdateStatement.executeUpdate();
    preUpdateStatement.close();
    null

    stack is:
    java.sql.SQLException: Io exception: Char array not long enough: javaCharsToUtf8Bytes
    at java.lang.Throwable.<init>(Compiled Code)
    at java.lang.Exception.<init>(Compiled Code)
    at java.sql.SQLException.<init>(Compiled Code)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(Compiled Code)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(Compiled Code)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.executeNonQuery(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithBatch(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.doExecute(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(Compiled Code)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(Compiled Code)

  • Open report using memorystream or byte array

    Dear All,
    I am using .Net4.0 with CR13, is it possible to load a report document using a memory stream or byte array in stead from a physical file from disk?
    If not, will this be made available?
    regards

    By default when you use the .Load() API CR creates a temp file in your users
    %Users%\AppData\Local\Temp folder so CR requires access to that folder at least. And therefore it also requires Virus and other permissions to use it.
    Bottom line is there is no Load or Open report from FileStream Method.
    Add it to Idea Place, search first though, someone may have already requested it.
    Don

  • JPA: Persist binary data (byte array)

    Hi,
       when trying to add a field to an entity to hold binary data as a Byte[] (array of objects) NWDS "finds" the following error:
    Class with name '[Ljava.lang.Byte;' not found
    If the field is of type byte[] (array of primitives):
    Class with name '[B' not found
    However, according to the JEE Tutorial (page 686), byte array and Byte array are valid types. Is the JPA implementation lacking this feature or am I missing something? Here the field declaration, including the annotations:
         @Column(name="IMPL_BINARY")
         @Lob
         private byte[] implBinary;
    Thank you for your help in advance.
    Cheers,
    Patrik

    Looks like you're using JDK 6 and Eclipse/WTP has the issue described [here|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6500212]. JDK 6 is not supported as runtime yet anyway, so even if you had been able to build your project, it would not run on the server. Therefore, I'd suggest that you switch to JDK 1.5.
    HTH!
    \-- Vladimir

  • System code 1, error 43. English text was "Expected an object Stream"

    All,
    I have been working on the same form for several weeks (In Livecycle 8.0). Today when I went to open it, I get the error message "Library returned system code 1, error 43. English text was "Expected an object Stream" " and the only option I have is to say okay, and the windows closes.
    Background:
    The Original Form was a MS Word Document that I converted to a pdf, and use Livecycle 8.0 to add drop down menus, fields etc. to it.
    We have been using the form in reader for days, (testing it) and it still works fine in adobe reader, we can still open it without any problems.
    However I needed to add more options to my drop down menu's and when I attempt to open the pdf file in Livecycle, all of sudden I get this error, system code 1, error 43.
    I have googled, it a didnt find any help, and I have looked / searched the knowledge base with no luck.
    Thank you for any assistance!
    duffie

    I have not seen that error ...can you email it to [email protected] and I will have a look

  • Root object in Object Stream in Encrypted file

    I cannot find anywhere in the PDF Spec a prohibition on including the Root object in an Object Stream in a non-linearized encrypted file, but Acrobat products appear to assume such a restriction.
    Encrypted files where the Root obj is in an Object Stream do not open with Acrobat 7, 8 or Reader 9, but do open with GhostView/Ghostscript, Foxit, and Adobe Digital Editions.
    If the file is not encrypted there is no problem with the Root object appearing in an Object Stream, and if the Root object is a 'normal' encrypted object there is also no problem.
    Anyone any ideas?
    Matthew Fitzgerald

    Hey praveen,
    If you dont use ehp1, there is no any transaction to create root object. you can fallow this [wiki|http://wiki.sdn.sap.com/wiki/display/CRM/CreateaZBOLObjectPart1] page.
    Regards,
    Zafer,

  • File Read and Byte Conversion Efficiency

    Im working on a program that needs to store WAV data.
    2 unsigned bytes Little Endian -> signed Short
    this is my code:
    fis = new BufferedInputStream(new FileInputStream(file), 1764000);
    for(int x = 0; x < wav.samples; x++){
    fis.read(byte2);
    wav.left[i] = (short)b2LEtoInt();
    public int b2LEtoInt(){
    i += (int)(byte2[1] & 0xff) << 8;
    i += (int)(byte2[0] & 0xff);
    if(i > 32767){ i -= 65536; }
    return i;
    }I set the buffer size to 1,764,000 bytes because that is fairly
    large and it is 10 seconds of 44100 16bit stereo WAV data.
    Reading 79,161,264 takes 8282 ms
    Waiting 8 seconds for almost 8 mins of WAV data isnt horrible
    but its markedly worse than WaveLAB or CoolEditPro etc that can
    load the same data and graph it pretty much as quickly as i can
    drag the file onto the screen.
    Is this a Java vs Native code speed problem or a design problem?
    Does anyone have any tips to speed up this loading process?
    I dont know if thats the best 2 byte little endian to short conversion.
    I dont know if im using the right reader / buffersize.
    I dont know how programs like WaveLAB work with wavs.
    Do they load them into memory completely? Are the graphs
    images that are then zoomed into or are they redrawn every
    time you move them?
    Anyone have any expert advice?

    is this right...
    the buffered reader grabs 1,765,000 bytes from the
    file automatically,
    read(byte[]...) then reads [x] many bytes from the
    reader?Yes but if your byte array has only 2 elements this read method will be called (1,765,000 /2) times and that was the problem. You can reduce by increasing the size of the array.
    What the buffered reader does is it minimze the IO blocks which will occure when you actualy read file from the disk buy redusing the niumber of Disk IOs.
    and also read method does not gurrantee that the exact number of bytes that you specify is read from the stream by read method
    (Read the java documentation of InputStream.read(byte[],int,int))
    it says that the maximum number of bytes that will be read is what you specified but the actual number read may be less than that and that depending on the implementation.
    read method return an integer value which is the actuall number of bytes I think you should get it in to a variable and use when processing

Maybe you are looking for

  • The iPod "iPod" could not be restored. An unknown error has occurred (11).

    I recieved an iPod from a friend of mine. He has bought a new one and is currently using it with his apple ID. I have plugged in the iPod he gave me and attempted to restore it. When it goes through most of the restoration process the error "The iPod

  • Internet explorer freezes computers

    I have 8 iMacs that are freezing when Internet Explorer is started. All are running 9.2.2. and All started this problem arund the same time. The computers are in a school and are in different rooms. 3 are eMacs. All have differing ammounts of Ram bui

  • IPhone 5 issue with using downloaded ringtone

    I have an iPhone5 & downloaded a ringtone from iTunes and cannot get it in my sound settings to use as ringtone. Does anyone know how to fix this issue?

  • Retrive logical names of table in oracle?

    Hi, Select * from tab; Gives the physical name of table.... How to retrive the logical name of table?

  • Mutated while being enumerated

    This is an error message I received in CC Photoshop after opening numerous files the consequence is I cannot open any more files unless I manually find them and double click (or drag and drop) this also happens in Illustrator but without the error me