WrappedOutputStream.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package me.hammerle.snuviengine.util;
  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. public class WrappedOutputStream
  5. {
  6. private final OutputStream out;
  7. public WrappedOutputStream(OutputStream out)
  8. {
  9. this.out = out;
  10. }
  11. public void writeByte(int b) throws IOException
  12. {
  13. out.write(b);
  14. }
  15. public void writeUnsignedByte(int b) throws IOException
  16. {
  17. out.write(b);
  18. }
  19. public void writeShort(int s) throws IOException
  20. {
  21. out.write(s & 0xFF);
  22. out.write((s >> 8) & 0xFF);
  23. }
  24. public void writeInt(int i) throws IOException
  25. {
  26. out.write(i & 0xFF);
  27. out.write((i >> 8) & 0xFF);
  28. out.write((i >> 16) & 0xFF);
  29. out.write((i >> 24) & 0xFF);
  30. }
  31. public void writeLong(long l) throws IOException
  32. {
  33. out.write((int) (l & 0xFF));
  34. out.write((int) ((l >> 8) & 0xFF));
  35. out.write((int) ((l >> 16) & 0xFF));
  36. out.write((int) ((l >> 24) & 0xFF));
  37. out.write((int) ((l >> 32) & 0xFF));
  38. out.write((int) ((l >> 40) & 0xFF));
  39. out.write((int) ((l >> 48) & 0xFF));
  40. out.write((int) ((l >> 56) & 0xFF));
  41. }
  42. public void writeString(String s) throws IOException
  43. {
  44. byte[] b = s.getBytes();
  45. writeInt(b.length);
  46. out.write(b);
  47. }
  48. }