Example usage for java.util.logging ErrorManager WRITE_FAILURE

List of usage examples for java.util.logging ErrorManager WRITE_FAILURE

Introduction

In this page you can find the example usage for java.util.logging ErrorManager WRITE_FAILURE.

Prototype

int WRITE_FAILURE

To view the source code for java.util.logging ErrorManager WRITE_FAILURE.

Click Source Link

Document

WRITE_FAILURE is used when a write to an output stream fails.

Usage

From source file:net.larry1123.elec.util.logger.UtilFileHandler.java

@Override
public synchronized void setOutputStream(OutputStream out) throws SecurityException {
    if (out == null) {
        throw new NullPointerException();
    }/*from  w  w  w .ja  v  a2s  .com*/
    try {
        memoryOutputStream.writeTo(out);
    } catch (IOException e) {
        reportError("Unable to move temp buffer!", e, ErrorManager.WRITE_FAILURE);
    }
    super.setOutputStream(out);
}

From source file:ffx.ui.LogHandler.java

/**
 * {@inheritDoc}//from  w ww .java 2s  . com
 *
 * Publish a LogRecord.
 *
 * @since 1.0.
 */
@Override
public synchronized void publish(LogRecord record) {
    if (record.getLevel() == Level.OFF) {
        if (record.getMessage().toLowerCase().contains("algorithm failure:")) {
            mainPanel.setExitType(MainPanel.ExitStatus.ALGORITHM_FAILURE);
        }
        return;
    }
    /**
     * Check if the record is loggable and that we have not already
     * encountered a fatal error.
     */
    if (!isLoggable(record) || fatal) {
        return;
    }
    String msg;
    try {
        msg = getFormatter().format(record);
    } catch (Exception e) {
        /**
         * We don't want to throw an exception here, but we report the
         * exception to any registered ErrorManager.
         */
        reportError(null, e, ErrorManager.FORMAT_FAILURE);
        return;
    }
    try {
        if (record.getLevel() == Level.SEVERE) {
            fatal = true;
            System.err.println(msg);

            Throwable throwable = record.getThrown();
            if (throwable != null) {
                System.err.println(String.format(" Exception %s logged.", throwable));
            }

            // If tryCatchSevere, and the throwable (if it exists) is not an Error, then...
            if (tryCatchSevere && (throwable == null || !(throwable instanceof Error))) {
                System.err.println(" Force Field X may not continue.");
                System.err.println(" Throwing new error...");
                fatal = false;
                if (throwable != null) {
                    throw new LoggerSevereError(throwable);
                } else {
                    throw new LoggerSevereError(" Unknown exception");
                }
            }

            System.err.println(" Force Field X will not continue.");
            System.err.println(" Shutting down...");
            flush();
            mainPanel.setExitType(MainPanel.ExitStatus.SEVERE);
            mainPanel.exit();
        }
        ModelingShell shell = null;
        if (mainPanel != null) {
            shell = mainPanel.getModelingShell();
        }

        if (!headless && shell != null) {
            shell.appendOutputNl(msg, shell.getResultStyle());
        } else {
            System.out.println(msg);
        }
    } catch (Exception e) {
        /**
         * We don't want to throw an exception here, but we report the
         * exception to any registered ErrorManager.
         */
        reportError(null, e, ErrorManager.WRITE_FAILURE);
    }
}