0

Looking through a couple different projects I can see two different namings for the same items.

Which one is correct/wrong or is more universally understood vs the other?

Project 1:

//reading
byte[] data;
InputStream is = new InputStream(data);
int value = is.getUnsignedByte();

//writing
OutputStream os = new OutputStream(16); //arg0 = capacity (not revelant here)
os.writeByte(value);

Project 2:

//reading
byte[] data;
ByteBufReader reader = new ByteBufReader(data);
int value = reader.getUnsigned(DataType.BYTE, DataOrder.REGULAR);

//writing
ByteBufBuilder builder = new ByteBufBuilder(16); //arg0 = capacity (not revelant here)
builder.put(DataType.BYTE, DataOrder.REGULAR, value);
kay
  • 451
  • 1
  • 3
  • 13

1 Answers1

0

Neither of classes is a class in the Java SE class library.

  • There is no ByteBufReader class.
  • There is an InputStream class, but its API is not compatible with the way your code is using it, some this class must be a different one.

Which is more correct? It really depends on what the actual classes do, and you haven't shown us the classes.

However, using the name InputStream is a mistake, no matter its "correctness". It is a bad idea to choose a class name that is the same as a common class name. It is bad for readability. And in this case, there are three existing InputStream classes ... in the Java 8 class library.

But to be honest, it looks like the code you are looking at should be using the existing (standard) ByteArrayInputStream and ByteArrayOutputStream classes.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Here both classes buffReader and InputStream represent a modified version of "org.omg.CORBA.portable.InputStream" (which does not extend or implement any existing Java class, but does essentially the same thing). – kay Sep 13 '18 at 13:33
  • That's not sufficient to answer your question. (And doesn't make a lot of sense ...) Please provide a link to the code ... or the javadoc if the javadoc is written properly. – Stephen C Sep 13 '18 at 13:44