Results 1 to 5 of 5

Thread: Java.. cant move an Enum to a ByteBuffer

  1. #1
    Join Date
    Oct 2007
    Location
    Melbourne, Australia
    Beans
    101
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Java.. cant move an Enum to a ByteBuffer

    Hi all

    Am trying to dump a class to a ByteBuffer.

    Am using Enums in the class and cant find a way to do it with latest J2SE on Ubuntu 10.10

    Compiles with an inconvertible type message. Is the answer to forget about using enums in Java at this point in time, or is there a way to do it


    Code:
    //      Simple page structure
    
    import java.awt.*;
    import java.nio.*;
    
    class Simp extends Object{
    
    public enum IpType{P0,IX,DT,DB;}
    
    IpType tag,type;
    Byte updated;
    static ByteBuffer stgB;
    int blk;
    
    private Simp(int pgSize){
            tag=IpType.DB; type=IpType.P0; updated=0; blk=0;}
    
    private int dump(){
            stgB=ByteBuffer.allocate(256);
            stgB.put((int)tag);
            stgB.put((int)type);
            stgB.put(updated);
            stgB.putInt(blk);
            return stgB.position();}
    
    }
    Any thoughts?

  2. #2
    Join Date
    Nov 2010
    Location
    Down the rabbit hole
    Beans
    435
    Distro
    Ubuntu Development Release

    Re: Java.. cant move an Enum to a ByteBuffer

    It looks like you're trying to serialize a class, if so, Java already has built-in support, just google around.
    Your ads here, just 9.99$/week !!

  3. #3
    Join Date
    Oct 2007
    Location
    Melbourne, Australia
    Beans
    101
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Java.. cant move an Enum to a ByteBuffer

    Thanks t149...

    What I am doing is very similar to serialiation.

    Am writing an ISAM type record handler, and need to pack records into datapages. This is just a general case which naturally used enums. Simply solved/avoided by replacing enums with "static Byte P0=1; ..."

    I talk to the ISAM record handler using sockets and serialization. I dont really want to impose a reader/writer overhead on simply moving records around and ByteBuffer gives me most of the functionality I want, maybe at 50% the efficiency of using C. Still way more efficient than RDMS systems.

    Thanks Bill

  4. #4
    Join Date
    Jul 2008
    Location
    England
    Beans
    866

    Re: Java.. cant move an Enum to a ByteBuffer

    I have found that ObjectInputStreams and ObjectOutputStreams are very useful and have little overhead to converting my data into byte streams.

    Given a little testing you may find that there isn't much difference and that you code is alot simpler.

    Paul

  5. #5
    Join Date
    Nov 2009
    Beans
    1,081

    Re: Java.. cant move an Enum to a ByteBuffer


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •