PrintWriter doesn't throw exceptions, so call checkError()

This commit is contained in:
zzz
2015-05-06 01:51:57 +00:00
parent 77c9a644ac
commit 2aafc23774
5 changed files with 13 additions and 0 deletions

View File

@ -87,6 +87,8 @@ abstract class PersistDHT {
out.println(ni.toPersistentString()); out.println(ni.toPersistentString());
count++; count++;
} }
if (out.checkError())
throw new IOException("Failed write to " + file);
} catch (IOException ioe) { } catch (IOException ioe) {
if (log.shouldLog(Log.WARN)) if (log.shouldLog(Log.WARN))
log.warn("Error writing the DHT File", ioe); log.warn("Error writing the DHT File", ioe);

View File

@ -112,6 +112,8 @@ public class SubscriptionsBean extends BaseBean
out.println(url); out.println(url);
} }
out.close(); out.close();
if (out.checkError())
throw new IOException("Failed write to " + file);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();

View File

@ -53,6 +53,8 @@ public class CertUtil {
} }
wr.println("-----END CERTIFICATE-----"); wr.println("-----END CERTIFICATE-----");
wr.flush(); wr.flush();
if (wr.checkError())
throw new IOException("Failed write to " + file);
return true; return true;
} catch (CertificateEncodingException cee) { } catch (CertificateEncodingException cee) {
error("Error writing X509 Certificate " + file.getAbsolutePath(), cee); error("Error writing X509 Certificate " + file.getAbsolutePath(), cee);

View File

@ -529,6 +529,11 @@ public class DataHelper {
out.flush(); out.flush();
fos.getFD().sync(); fos.getFD().sync();
out.close(); out.close();
if (out.checkError()) {
out = null;
tmpFile.delete();
throw new IOException("Failed to write properties to " + tmpFile);
}
out = null; out = null;
if (!FileUtil.rename(tmpFile, file)) if (!FileUtil.rename(tmpFile, file))
throw new IOException("Failed rename from " + tmpFile + " to " + file); throw new IOException("Failed rename from " + tmpFile + " to " + file);

View File

@ -322,6 +322,8 @@ public class WorkingDir {
out.println(s); out.println(s);
} }
System.err.println("Copied " + oldFile + " with modifications"); System.err.println("Copied " + oldFile + " with modifications");
if (out.checkError())
throw new IOException("Failed write to " + newFile);
return true; return true;
} catch (IOException ioe) { } catch (IOException ioe) {
if (in != null) { if (in != null) {