There is a method that finds indices of subString occurrences in inStream (actually it's a file)
public static ArrayList<Long> searchSubStrings(InputStream inStream, String subString) throws IOException {
ArrayList<Long> indexes = new ArrayList<>();
String subStringName = new String(subString.getBytes(),StandardCharsets.UTF_8);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, StandardCharsets.UTF_8))) { // one more battle
int ch; //
long headSubstring = 0; // write here position in file of substring's beginning
long currPosInFile = 0; // we go through the file char by char
int currPosInSubstring = 0; //
boolean isSubString = false;
while ((ch = reader.read()) != -1) {
/*cool algo*/
}
} catch (IOException e) {
e.printStackTrace();
}
return indexes;
}
What are the pros and cons of handling the exception here?
also I use reader.reset();
in /cool algo/ and I'm not sure that BufferedReader won't start reading from file after reset call.