Codice: Seleziona tutto
private String parseString(final BufferedReader reader, final String name1, final String name2, final boolean skipLast) throws DatiMeseInvalidiException {
try {
final String input = reader.readLine();
if (input != null && !input.trim().isEmpty() && (input.startsWith(name1) || input.startsWith(name2))) {
int index = input.indexOf(":");
if (index < 0) {
throw new DatiMeseInvalidiException("Identificatore non presente");
}
if (skipLast) {
int indexV = input.indexOf(",");
return input.substring(index + 1, indexV);
} else {
return input.substring(index + 1);
}
}
throw new DatiMeseInvalidiException("Identificatore non presente");
} catch (IOException ex) {
Logger.getLogger(ApriFileMese.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
Se non trova i dati nell'ordine prestabilito o le righe sono vuote lancia una eccezione:
Codice: Seleziona tutto
public class DatiMeseInvalidiException extends Exception {
public DatiMeseInvalidiException(String message) {
super(message);
JOptionPane.showMessageDialog(null,
"It's impossible to get the information.",
"Warning",
JOptionPane.WARNING_MESSAGE);
}
}
Codice: Seleziona tutto
....
SEVERE: null
pv.DatiMeseInvalidiException: Identificatore non presente
...
Come posso risolvere ?
Grazie