public final void readFully(final byte b[], final int off, final int len) throws IOException { // this may look over-complicated, but the problem is that the InputStream.read() methods are // not guaranteed to fill up the buffer you pass to it. So we need to loop until we have filled // up the buffer or until we reach the end of the file. final int bytesRead = _stream.read(b, off, len); if (bytesRead == -1) { throw new EOFException("EOF reached"); } if (bytesRead < len) { // we didn't get all the data we wanted, so read some more readFully(b, off + bytesRead, len - bytesRead); } }
public final void readFully(final byte b[], final int off, final int len) throws IOException { // this may look over-complicated, but the problem is that the InputStream.read() methods are // not guaranteed to fill up the buffer you pass to it. So we need to loop until we have filled // up the buffer or until we reach the end of the file. final int bytesRead = _stream.read(b, off, len); if (bytesRead == -1) { throw new EOFException("EOF reached"); } if (bytesRead < len) { // we didn't get all the data we wanted, so read some more readFully(b, off + bytesRead, len - bytesRead); } }
static final ByteBuffer readDXT(final LittleEndianDataInput in, final int totalSize, final DdsImageInfo info, final Image image) throws IOException { int mipWidth = info.header.dwWidth; int mipHeight = info.header.dwHeight; final ByteBuffer buffer = BufferUtils.createByteBuffer(totalSize); for (int mip = 0; mip < info.header.dwMipMapCount; mip++) { final byte[] data = new byte[info.mipmapByteSizes[mip]]; in.readFully(data); if (!info.flipVertically) { buffer.put(data); } else { final byte[] flipped = flipDXT(data, mipWidth, mipHeight, image.getDataFormat()); buffer.put(flipped); mipWidth = Math.max(mipWidth / 2, 1); mipHeight = Math.max(mipHeight / 2, 1); } } buffer.rewind(); return buffer; }
static final ByteBuffer readDXT(final LittleEndianDataInput in, final int totalSize, final DdsImageInfo info, final Image image) throws IOException { int mipWidth = info.header.dwWidth; int mipHeight = info.header.dwHeight; final ByteBuffer buffer = BufferUtils.createByteBuffer(totalSize); for (int mip = 0; mip < info.header.dwMipMapCount; mip++) { final byte[] data = new byte[info.mipmapByteSizes[mip]]; in.readFully(data); if (!info.flipVertically) { buffer.put(data); } else { final byte[] flipped = flipDXT(data, mipWidth, mipHeight, image.getDataFormat()); buffer.put(flipped); mipWidth = Math.max(mipWidth / 2, 1); mipHeight = Math.max(mipHeight / 2, 1); } } buffer.rewind(); return buffer; }
public void run() { try { littleEndien.readFully(array); } catch (IOException e) { e.printStackTrace(); fail("ioexception"); } } });
for (int x = 0; x < mipWidth; x++) { final byte[] b = new byte[sourcebytesPP]; in.readFully(b);
for (int x = 0; x < mipWidth; x++) { final byte[] b = new byte[sourcebytesPP]; in.readFully(b);
@Test public void testReadFully2() throws Exception { in.addBytesAvailable(11240); littleEndien.readFully(array, 0, 4); // not caring about whether the bytes were actually copied successfully in this test }
@Test public void testReadFully1() throws Exception { in.addBytesAvailable(11111); littleEndien.readFully(array); // not caring about whether the bytes were actually copied successfully in this test }
@Test (expected = EOFException.class) public void testReadFully4() throws Exception { in.setEof(true); littleEndien.readFully(array); // not caring about whether the bytes were actually copied successfully in this test } }