You don't need this copy. Just do oStream.write(ptr.get(), ptr.getOffset(), ptr.getLenth());