public void skipInt() throws IOException { skip(4); }
public GenericChunk(ChunkType chunkType, IntReader reader) { startPosition = reader.getBytesRead() - 4; type = chunkType; try { size = reader.readInt(); readHeader(reader); } catch (IOException exception) { // TODO : Handle this better exception.printStackTrace(); } }
private void readPool(ArrayList<PoolItem> pool, int flags, IntReader inputReader) throws IOException { int offset = 0; for (PoolItem item : pool) { // TODO: This assumes that the pool is ordered... inputReader.skip(item.getOffset() - offset); offset = item.getOffset(); int length = 0; if ((flags & UTF8_FLAG) != 0) { length = inputReader.readByte(); offset += 1; } else { length = inputReader.readShort(); offset += 2; } StringBuilder result = new StringBuilder(length); for (; length != 0; length -= 1) { if ((flags & UTF8_FLAG) != 0) { result.append((char) inputReader.readByte()); offset += 1; } else { result.append((char) inputReader.readShort()); offset += 2; } } item.setString(result.toString()); } }
public GenericChunkSection(ChunkType chunkType, IntReader reader) { super(chunkType, reader); try { readSection(reader); reader.skip(Math.abs(reader.getBytesRead() - getStartPosition() - size)); } catch (IOException e) { // Catching this here allows us to continue reading e.printStackTrace(); } }
public boolean read(InputStream stream) throws IOException { IntReader reader = new IntReader(stream, false); while ((size - reader.getBytesRead()) > 4) { if (header.getSize() != reader.getBytesRead()) { System.out.println("Potential issue as the bytes read is not equal to the amount of bytes in the file");
@Test public void testReadIntLittleEndian() throws IOException { underTest = new IntReader(mockStream, false); when(mockStream.read()).thenReturn(10).thenReturn(20).thenReturn(30).thenReturn(40); assertEquals(10, underTest.readInt(1)); assertEquals(((20 << 0) | (30 << 8) | (40 << 16)), underTest.readInt(3)); } }
/*chunkSize*/m_reader.skipInt(); m_strings=StringBlock.read(m_reader); m_namespaces.increaseDepth(); chunkType=m_reader.readInt(); int chunkSize=m_reader.readInt(); if (chunkSize<8 || (chunkSize%4)!=0) { throw new IOException("Invalid resource ids size ("+chunkSize+")."); m_resourceIDs=m_reader.readIntArray(chunkSize/4-2); continue; /*chunkSize*/m_reader.skipInt(); int lineNumber=m_reader.readInt(); /*0xFFFFFFFF*/m_reader.skipInt(); int prefix=m_reader.readInt(); int uri=m_reader.readInt(); m_namespaces.push(prefix,uri); } else { /*prefix*/m_reader.skipInt(); /*uri*/m_reader.skipInt(); m_namespaces.pop(); m_namespaceUri=m_reader.readInt(); m_name=m_reader.readInt(); /*flags?*/m_reader.skipInt(); int attributeCount=m_reader.readInt();
@Test public void testSkips() throws IOException { when(mockStream.skip(8)).thenReturn(8L); when(mockStream.skip(4)).thenReturn(4L); // Nothing happens underTest.skip(0); // Skip 8 underTest.skip(8); // Skip 4 underTest.skipInt(); verify(mockStream, times(1)).skip(8); verify(mockStream, times(1)).skip(4); }
public IntReader(InputStream stream, boolean bigEndian) { reset(stream, bigEndian); }
int chunkSize=reader.readInt(); int stringCount=reader.readInt(); int styleOffsetCount=reader.readInt(); /*?*/reader.readInt(); int stringsOffset=reader.readInt(); int stylesOffset=reader.readInt(); block.m_stringOffsets=reader.readIntArray(stringCount); if (styleOffsetCount!=0) { block.m_styleOffsets=reader.readIntArray(styleOffsetCount); throw new IOException("String data size is not multiple of 4 ("+size+")."); block.m_strings=reader.readIntArray(size/4); throw new IOException("Style data size is not multiple of 4 ("+size+")."); block.m_styles=reader.readIntArray(size/4);
public void open(InputStream stream) { close(); if (stream!=null) { m_reader=new IntReader(stream,false); } }
@Test public void testReadShort() throws IOException { underTest.readShort(); verify(mockStream, times(2)).read(); }
@Test public void testReadByte() throws IOException { underTest.readByte(); verify(mockStream, times(1)).read(); }
public void close() { if (!m_operational) { return; } m_operational=false; m_reader.close(); m_reader=null; m_strings=null; m_resourceIDs=null; m_namespaces.reset(); resetEventInfo(); }
@Test public void testSkipFails() throws IOException { when(mockStream.skip(4)).thenReturn(-1L); try { underTest.skipInt(); throw new AssertionError("Excepted exception!"); } catch (IOException exception) { // Good case } }
private void readPool(ArrayList<PoolItem> pool, int flags, IntReader inputReader) throws IOException { int offset = 0; for (PoolItem item : pool) { // TODO: This assumes that the pool is ordered... inputReader.skip(item.getOffset() - offset); offset = item.getOffset(); int length = 0; if ((flags & UTF8_FLAG) != 0) { length = inputReader.readByte(); offset += 1; } else { length = inputReader.readShort(); offset += 2; } StringBuilder result = new StringBuilder(length); for (; length != 0; length -= 1) { if ((flags & UTF8_FLAG) != 0) { result.append((char) inputReader.readByte()); offset += 1; } else { result.append((char) inputReader.readShort()); offset += 2; } } item.setString(result.toString()); } }
public GenericChunkSection(ChunkType chunkType, IntReader reader) { super(chunkType, reader); try { readSection(reader); reader.skip(Math.abs(reader.getBytesRead() - getStartPosition() - size)); } catch (IOException e) { // Catching this here allows us to continue reading e.printStackTrace(); } }