GenericScanFileDateExtractor extends BaseScanDateExtractor { @Override public Date extract( InputStream is ) throws IOException { Date date = null; try (BufferedReader reader = new BufferedReader( new InputStreamReader( is ) )) { String line; int count = 0; while ( ( line = reader.readLine() ) != null ) { if ( line.matches( BaseScanDateExtractor.GENEPIX_DATETIME_HEADER_REGEXP ) ) { date = this.parseGenePixDateTime( line ); } if ( date == null ) { Pattern regex = Pattern.compile( ".+?([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}).+" ); Matcher matcher = regex.matcher( line ); if ( matcher.matches() ) { String tok = matcher.group( 1 ); date = this.parseISO8601( tok ); } } if ( date == null ) date = this.parseStandardFormat( line ); if ( date == null ) date = this.parseLongFormat( line ); if ( date != null || ++count > GenericScanFileDateExtractor.MAX_HEADER_LINES ) { if ( date != null && date.after( new Date() ) ) { throw new RuntimeException( "Did not get a valid date (Line was:" + line + ", extracted date was " + date + ")" ); } break; } } } return date; }  @Override Date extract( InputStream is );  }
@Test public void testExtractGeneSpring() throws Exception { try (InputStream is = this.getClass() .getResourceAsStream( "/data/loader/expression/geo/GSM522322.part.genespring.txt" )) { GenericScanFileDateExtractor extractor = new GenericScanFileDateExtractor(); Date actual = extractor.extract( is ); DateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" ); Date expected = formatter.parse( "2005-08-30T15:17:28" ); assertEquals( expected, actual ); } }
@Test public void testExtractGpr() throws Exception { InputStream is = new GZIPInputStream( this.getClass().getResourceAsStream( "/data/loader/expression/rawdata/GSM489680.short.gpr.gz" ) ); GenericScanFileDateExtractor extractor = new GenericScanFileDateExtractor(); Date actual = extractor.extract( is ); DateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" ); Date expected = formatter.parse( "2008-11-27T10:27:42" ); assertEquals( expected, actual ); }
@Test public void testExtractImagene() throws Exception { try (InputStream is = this.getClass() .getResourceAsStream( "/data/loader/expression/geo/GSM542196.imagene.part.txt" )) { GenericScanFileDateExtractor extractor = new GenericScanFileDateExtractor(); Date actual = extractor.extract( is ); DateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss zzz" ); Date expected = formatter.parse( "2002-06-17T20:26:36 PDT" ); assertEquals( expected, actual ); } }