agave-files/files-core/src/main/java/org/iplantc/service/io/util/GrepUtil.java
/**
	 * Most files won't be local, so we need to stream a portion of them in from the remote store
	 * to process for file type info.
	 * 
	 * @param uri
	 * @return
	 * @throws IOException
	 * @throws RemoteDataException 
	 * @throws URISyntaxException 
	 */
Most files won't be local, so we need to stream a portion of them in from the remote store
to process for file type info.


Most files won ' t be local so we need to stream a portion of them in from the remote store to process for file type info .
@SuppressWarnings({ "unused" })
	public boolean grep(RemoteDataClient client, String remotePath) throws RemoteDataException, IOException {
		InputStream fis = null;
		try {
			fis = client.getInputStream(remotePath, true);
			byte[] bytes = new byte[4096]; 
			fis.read(bytes, 0, bytes.length);
			fis.close();
			String s = new String(bytes);
			Matcher lm = linePattern.matcher(s); 
			Matcher pm = null; 
			int lines = 0;
			while (lm.find()) 
			{
				lines++;
				CharSequence cs = lm.group(); 
				if (pm == null)
					pm = pattern.matcher(cs);
				else
					pm.reset(cs);
				if (pm.find()) {
					log.debug("Found matching line " + cs);
					return true;
				}
				if (s.endsWith(cs.toString()))
					break;
			}
			return false;
		} 
		finally 
		{
			try { fis.close(); } catch (Exception e) {}
			try { client.disconnect(); } catch (Exception e) {}
		}
	}
@ SuppressWarnings ( { "unused" } ) public boolean grep ( RemoteDataClient client , String remotePath ) throws RemoteDataException , IOException { InputStream fis = null ; try { fis = client . getInputStream ( remotePath , true ) ; byte [ ] bytes = new byte [ 4096 ] ; fis . read ( bytes , 0 , bytes . length ) ; fis . close ( ) ; String s = new String ( bytes ) ; Matcher lm = linePattern . matcher ( s ) ; Matcher pm = null ; int lines = 0 ; while ( lm . find ( ) ) { lines ++ ; CharSequence cs = lm . group ( ) ; if ( pm == null ) pm = pattern . matcher ( cs ) ; else pm . reset ( cs ) ; if ( pm . find ( ) ) { log . debug ( "Found matching line " + cs ) ; return true ; } if ( s . endsWith ( cs . toString ( ) ) ) break ; } return false ; } finally { try { fis . close ( ) ; } catch ( Exception e ) { } try { client . disconnect ( ) ; } catch ( Exception e ) { } } }
Most files won't be local, so we need to stream a portion of them in from the remote store
 to process for file type info.
Most files won ' t be local so we need to stream a portion of them in from the remote store to process for file type info .
// Open the file and then get a channel from the stream // increase to parse more of the input file // Line matcher // Pattern matcher // The current line // Close the channel and the stream