NativeIStream.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file NativeIStream.java
  10. * @author rdb
  11. * @date 2013-01-22
  12. */
  13. package org.panda3d.android;
  14. import java.io.InputStream;
  15. /**
  16. * An implementation of InputStream that gets its data from a C++ istream
  17. * pointer, passed as long.
  18. */
  19. public class NativeIStream extends InputStream {
  20. private long streamPtr = 0;
  21. public NativeIStream(long ptr) {
  22. streamPtr = ptr;
  23. }
  24. @Override
  25. public int read() {
  26. return nativeGet(streamPtr);
  27. }
  28. @Override
  29. public int read(byte[] buffer, int offset, int length) {
  30. return nativeRead(streamPtr, buffer, offset, length);
  31. }
  32. @Override
  33. public long skip(long n) {
  34. return nativeIgnore(streamPtr, n);
  35. }
  36. private static native int nativeGet(long ptr);
  37. private static native int nativeRead(long ptr, byte[] buffer, int offset, int length);
  38. private static native long nativeIgnore(long ptr, long offset);
  39. }