public Set<String> convert(File file)
	{
		
		if(file.isDirectory())
		{
			//loop thru each directory
			Set<String> emails = new HashSet<String>();
					
			try (DirectoryStream<Path> stream = Files.newDirectoryStream(file.toPath())) 
			{
			    for (Path path: stream) 
			    {
			    	Set<String> results = convert(path.toFile());
			    	
			    	if(!results.isEmpty())
			    	{
			    		emails.addAll(results);
			    	}
			    }
			    
			    return emails;
			}
			catch(IOException e)
			{
				throw new SystemException("Unable to convert file:"+file+" error:"+e.getMessage(),e);
			}
		}
		else
		{
			Path path = file.toPath();
			PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.{json,txt,csv,xml,yml}");
			if(!pathMatcher.matches(path))
				return Collections.emptySet(); 
			try
			{
				List<String> list = Files.readAllLines(path);
				
				if(list == null)
					return Collections.emptySet();
				
				Set<String> emails =  list.stream().map(line -> 
				{ 
					Set<String> set = textToEmailsConverter.convert(line);
					if(set == null)
						set = Collections.emptySet();
					return set;
				}).flatMap(Collection::stream).collect(Collectors.toSet());
				
				return emails;
			}
			catch (IOException e)
			{
				throw new SystemException("Unable to convert file:"+file+" error:"+e.getMessage(),e);
			}
		}
		
	}
public Set < String > convert ( File file ) { if ( file . isDirectory ( ) ) { Set < String > emails = new HashSet < String > ( ) ; try ( DirectoryStream < Path > stream = Files . newDirectoryStream ( file . toPath ( ) ) ) { for ( Path path : stream ) { Set < String > results = convert ( path . toFile ( ) ) ; if ( ! results . isEmpty ( ) ) { emails . addAll ( results ) ; } } return emails ; } catch ( IOException e ) { throw new SystemException ( "Unable to convert file:" + file + " error:" + e . getMessage ( ) , e ) ; } } else { Path path = file . toPath ( ) ; PathMatcher pathMatcher = FileSystems . getDefault ( ) . getPathMatcher ( "glob:**/*.{json,txt,csv,xml,yml}" ) ; if ( ! pathMatcher . matches ( path ) ) return Collections . emptySet ( ) ; try { List < String > list = Files . readAllLines ( path ) ; if ( list == null ) return Collections . emptySet ( ) ; Set < String > emails = list . stream ( ) . map ( line -> { Set < String > set = textToEmailsConverter . convert ( line ) ; if ( set == null ) set = Collections . emptySet ( ) ; return set ; } ) . flatMap ( Collection :: stream ) . collect ( Collectors . toSet ( ) ) ; return emails ; } catch ( IOException e ) { throw new SystemException ( "Unable to convert file:" + file + " error:" + e . getMessage ( ) , e ) ; } } }
@param file the file or directory
@return the set of the emails in files