, . , , , , . , - . IOException . , RuntimeException / .
, , , , - .
true , , , .
try/finally, , , . - , try/catch.
, - , ; java.io.BufferedOutputStream ObjectOutputStream.
, :
private static final int MAX_ENTRIES_ALLOWED = 100;
private static final long MAX_FILE_SIZE = 1L * 1024 * 1024;
protected boolean removeEldestEntry(Map.Entry eldest) {
if (size() <= MAX_ENTRIES_ALLOWED) {
return false;
}
File objFile = new File("t.tmp");
if (objFile.length() > MAX_FILE_SIZE) {
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(objFile, true);
ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(fos));
oos.writeObject(eldest.getValue());
oos.close();
return true;
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e2) {
}
}
}
}