tahg

Untitled

Aug 4th, 2011
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. package org.bukkit.craftbukkit.util;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6.  
  7. public class VarInt {
  8. public static long read(DataInputStream stream) throws IOException {
  9. long value = 0;
  10. byte b;
  11. while((b = stream.readByte()) >= 0) {
  12. value = (value << 8) + b;
  13. }
  14. return (value << 8) + b + 128;
  15. }
  16.  
  17. public static void write(DataOutputStream stream, long l) throws IOException {
  18. int count = 64 - Long.numberOfLeadingZeros(l);
  19. count -= count % 7;
  20. for (int i = count; i > 0; i -=7) {
  21. stream.writeByte((int) ((l >>> i) & 0x3F));
  22. }
  23. stream.write((int) ((l & 0x3F) - 128));
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment