0

I want to write an enum value and store it to disk by saving a field from it with ByteBuffer.putShort() and writing that to disk. This enum is basically a field in a file header.

How much space does ByteBuffer.putShort() occupy?

user207421
  • 305,947
  • 44
  • 307
  • 483
user1071840
  • 3,522
  • 9
  • 48
  • 74

1 Answers1

0

As you haven't stated how you're writing it to disk, the question is unanswerable.

If however you're referring to serialization, the answer is 'no', as the enum is basically serialized as its string name plus a tag and some type information.

EDIT According to your comments and edits, you're actually asking whether putShort() writes 16 bits. That's answered in the documentation, and it has nothing to do with how big an enum is.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I want to save it's value to a ByteBuffer and write that to disk – user1071840 Nov 06 '13 at 21:48
  • How you serialize it will determine how much space it will take. If you used a string, then it will be the size of that string in the encoding you choose. – Giovanni Botta Nov 06 '13 at 21:49
  • Please see the edits. If I do putShort on a ByteBuffer and save the result from 'getTestValue()', that should help me save only 2 bytes? [Serialize the enum to 2 bytes] – user1071840 Nov 06 '13 at 21:54
  • If you're calling `ByteBuffer.putShort`, that will only write exactly 2 bytes. – Louis Wasserman Nov 06 '13 at 22:20
  • @user1071840 Writing a short doesn't constitute serialization in any way shape or form, but it is still documented how many bytes putShort() writes. Two. See the Javadoc. – user207421 Nov 07 '13 at 00:29