AffyScanDateExtractor extends BaseScanDateExtractor { @Override public Date extract( InputStream is ) { try (DataInputStream str = new DataInputStream( is )) { BufferedReader reader; Date date = null; int magic = this.readByte( str ); switch ( magic ) { case 64: { int version = this.readIntLittleEndian( str ); if ( version != 4 ) { throw new IllegalStateException( "Affymetrix CEL format not recognized: " + version ); } AffyScanDateExtractor.log.debug( this.readShort( str ) ); AffyScanDateExtractor.log.debug( this.readShort( str ) ); AffyScanDateExtractor.log.debug( this.readIntLittleEndian( str ) ); int headerLen = this.readShort( str ); if ( headerLen == 0 ) { headerLen = 800; } AffyScanDateExtractor.log.debug( headerLen ); StringBuilder buf = new StringBuilder(); for ( int i = 0; i < headerLen; i++ ) { buf.append( new String( new byte[] { str.readByte() }, "US-ASCII" ) ); } String[] headerLines = StringUtils.split( buf.toString(), "\n" ); for ( String string : headerLines ) { if ( string.startsWith( "DatHeader" ) ) { date = this.parseStandardFormat( string ); break; } } break; } case 59: { int version = this.readUnsignedByte( str ); if ( version != 1 ) { throw new IllegalStateException( "Affymetrix CEL format not recognized: " + version ); } @SuppressWarnings("unused") int numDataGroups = this .readIntBigEndian( str ); @SuppressWarnings("unused") int filePosOfFirstGroup = this .readIntBigEndian( str ); date = this.parseGenericCCHeader( str ); if ( date == null ) { date = this.parseGenericCCHeader( str ); } break; } default: reader = new BufferedReader( new InputStreamReader( is ) ); String line; int count = 0; while ( ( line = reader.readLine() ) != null ) { if ( line.startsWith( "DatHeader" ) ) { date = this.parseStandardFormat( line ); } if ( date != null || ++count > 100 ) { reader.close(); break; } } break; } if ( date == null ) { throw new IllegalStateException( "Failed to find date" ); } AffyScanDateExtractor.log.debug( date ); return date; } catch ( IOException e ) { throw new RuntimeException( e ); } }  @Override Date extract( InputStream is ); @SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use Date parseGenericCCHeader( DataInputStream str );  }
@Test public void testExtractInputStreamGCOS() throws Exception { InputStream is = new GZIPInputStream( this.getClass().getResourceAsStream( "/data/loader/expression/geo/GSM506974.part.CEL.gz" ) ); AffyScanDateExtractor extractor = new AffyScanDateExtractor(); Date actual = extractor.extract( is ); DateFormat formatter = new SimpleDateFormat( "MM/dd/yy hh:mm:ss" ); Date expected = formatter.parse( "08/15/08 7:15:36" ); assertEquals( expected, actual ); }
@Test public void testExtractInputStreamV3() throws Exception { InputStream is = new GZIPInputStream( this.getClass().getResourceAsStream( "/data/loader/expression/geo/GSM3448.part.CEL.txt.gz" ) ); AffyScanDateExtractor extractor = new AffyScanDateExtractor(); Date actual = extractor.extract( is ); DateFormat formatter = new SimpleDateFormat( "MM/dd/yy HH:mm:ss" ); Date expected = formatter.parse( "03/15/01 12:16:30" ); assertEquals( expected, actual ); }
@Test public void testExtractInputStreamV4() throws Exception { InputStream is = new GZIPInputStream( this.getClass().getResourceAsStream( "/data/loader/expression/geo/GSM306831.part.CEL.gz" ) ); AffyScanDateExtractor extractor = new AffyScanDateExtractor(); Date actual = extractor.extract( is ); DateFormat formatter = new SimpleDateFormat( "MM/dd/yy HH:mm:ss" ); Date expected = formatter.parse( "09/09/05 12:14:40" ); assertEquals( expected, actual ); }
@Test public void testExtractInputStreamVx() throws Exception { InputStream is = new GZIPInputStream( this.getClass().getResourceAsStream( "/data/loader/expression/geo/GSM239803.CEL.gz" ) ); AffyScanDateExtractor extractor = new AffyScanDateExtractor(); Date actual = extractor.extract( is ); DateFormat formatter = new SimpleDateFormat( "MM/dd/yy hh:mm:ss" ); Date expected = formatter.parse( "01/20/05 11:04:38" ); assertEquals( expected, actual ); }