PgxProductReader extends AbstractProductReader { static Header parseHeaderLine(String headerLine) { StringTokenizer st = new StringTokenizer(headerLine); try { final int nTokens = st.countTokens(); if (!(st.nextToken()).equals("PG")) { return null; } final ByteOrder byteOrder; String tmp = st.nextToken(); if (tmp.equals("LM")) { byteOrder = ByteOrder.LITTLE_ENDIAN; } else if (tmp.equals("ML")) { byteOrder = ByteOrder.BIG_ENDIAN; } else { return null; } final boolean signed; if (nTokens == 6) { tmp = st.nextToken(); if (tmp.equals("+")) { signed = false; } else if (tmp.equals("-")) { signed = true; } else { return null; } } else { signed = false; } final int bitDepth; final int width; final int height; try { bitDepth = new Integer(st.nextToken()); if ((bitDepth <= 0) || (bitDepth > 31)) { return null; } width = new Integer(st.nextToken()); height = new Integer(st.nextToken()); return new Header(byteOrder, signed, bitDepth, width, height); } catch (NumberFormatException e) { return null; } } catch (NoSuchElementException e) { return null; } } PgxProductReader(PgxProductReaderPlugIn readerPlugIn); @Override void close();  }
@Test public void testHeaderParsing() { final PgxProductReader.Header header = PgxProductReader.parseHeaderLine("PG ML + 16 10960 4096"); assertNotNull(header); assertEquals(ByteOrder.BIG_ENDIAN, header.byteOrder); assertEquals(false, header.signed); assertEquals(16, header.bitDepth); assertEquals(10960, header.width); assertEquals(4096, header.height); }
@Test public void testHeaderParsing_WrongHeader() { assertNull(PgxProductReader.parseHeaderLine("gernuigh589z589nerjkghrepgöniofh89348")); }