5

I am curious to know if there is anything like the Cocoa NSData Class on Java. I have looked around but I can't find anything. I want to make a file sharing client server application.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tushar Chutani
  • 1,522
  • 5
  • 27
  • 57
  • Can you provide a link or explain what is this "NSData" type you mention? – maerics Aug 12 '11 at 16:03
  • Please have a look at the apple [Docs](http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html) – Tushar Chutani Aug 12 '11 at 16:04

4 Answers4

8

ByteBuffer?

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
2

Not sure exactly what you are looking for, but would byte[] suffice?

Goibniu
  • 2,212
  • 3
  • 34
  • 38
0

A simple byte[] can not be resized. There are some cases where additional data may be needed to inject at the end of byte[] so in that case you have to fully create a new byte[] array each time a modification is needed to sent which is rather a performance issue also.

ArrayList is flexible. You create once and can send additional data by injecting at the end of ArrayList, as well as no need to recreated the ArrayList to modify bytes.

0

Try an ArrayList<Byte>. http://download.oracle.com/javase/1.4.2/docs/api/java/util/ArrayList.html

ryanrhee
  • 2,550
  • 4
  • 23
  • 25
  • Yikes. Every `byte` would need to be wrapped in a `Byte` instance, and unwrapped on each access. A simple `byte[]` array would be much more efficient. – Greg Brown Jul 22 '16 at 12:47