Java Code Examples for org.osgl.util.IO#close()

The following examples show how to use org.osgl.util.IO#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppScanner.java    From actframework with Apache License 2.0 6 votes vote down vote up
private ProjectLayout probeLayoutPropertiesFile(File appBase) {
    File f = new File(appBase, ProjectLayout.PROJ_LAYOUT_FILE);
    if (f.exists() && f.canRead()) {
        Properties p = new Properties();
        InputStream is = IO.is(f);
        try {
            p.load(is);
        } catch (IOException e) {
            throw E.ioException(e);
        } finally {
            IO.close(is);
        }
        return ProjectLayout.util.build(p);
    } else {
        return null;
    }
}
 
Example 2
Source File: SimpleMetricStore.java    From actframework with Apache License 2.0 6 votes vote down vote up
void write(SimpleMetricStore store) {
    if (ioError) {
        return;
    }
    ObjectOutputStream oos = null;
    try {
        File file = new File(FILE_NAME);
        oos = new ObjectOutputStream(new FileOutputStream(file));
        oos.writeObject(store);
    } catch (IOException e) {
        ioError = true;
        throw E.ioException(e);
    } finally {
        IO.close(oos);
    }
}
 
Example 3
Source File: Destroyable.java    From actframework with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to destroy all {@link Destroyable} elements,
 * and close all {@link Closeable} elements in the collection specified
 *
 * @param col   the collection might contains {@link Destroyable} and
 *              {@link Closeable} elements
 * @param scope specify the scope annotation.
 */
public static void tryDestroyAll(Collection<?> col, Class<? extends Annotation> scope) {
    if (null == col) {
        return;
    }
    for (Object o : col) {
        if (inScope(o, scope)) {
            try {
                if (o instanceof Destroyable) {
                    ((Destroyable) o).destroy();
                }
            } catch (Exception e) {
                Act.LOGGER.warn(e, "Error encountered destroying instance of %s", o.getClass().getName());
                // keep destroy next one
            }
            if (o instanceof Closeable) {
                IO.close((Closeable) o);
            }
        }
    }

    //col.clear();
}
 
Example 4
Source File: Interaction.java    From actframework with Apache License 2.0 6 votes vote down vote up
private boolean verify() {
    Response resp = null;
    try {
        if (S.notBlank(request.email)) {
            doVerifyEmail(request.email);
        } else {
            resp = TestSession.current().sendRequest(request);
            doVerify(resp);
        }
        return true;
    } catch (Exception e) {
        errorMessage = e.getMessage();
        if (null == errorMessage) {
            errorMessage = e.getClass().getName();
        }
        cause = causeOf(e);
        return false;
    } finally {
        IO.close(resp);
    }
}
 
Example 5
Source File: ConfLoader.java    From actframework with Apache License 2.0 6 votes vote down vote up
private Map loadConfFromFile(File conf) {
    if (isTraceEnabled()) {
        trace("loading app conf from file: %s", conf);
    }
    if (!conf.canRead()) {
        logger.warn("Cannot read conf file[%s]", conf.getAbsolutePath());
        return new HashMap<>();
    }
    InputStream is = IO.inputStream(conf);
    Properties p = new Properties();
    try {
        p.load(is);
        return p;
    } catch (Exception e) {
        logger.warn(e, "Error loading %s", confFileName());
    } finally {
        IO.close(is);
    }
    return new HashMap<>();
}
 
Example 6
Source File: UndertowNetwork.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
protected void close() {
    if (null == channels) {
        // not booted yet
        return;
    }
    for (AcceptingChannel<? extends StreamConnection> channel : channels) {
        IO.close(channel);
    }
    channels.clear();
    worker.shutdownNow();
}
 
Example 7
Source File: ZXingResult.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
protected void applyMessage(H.Request request, H.Response response) {
    String msg = this.getMessage();
    this.applyBeforeCommitHandler(request, response);
    if(S.notBlank(msg)) {
        renderCode(response);
    } else {
        IO.close(response.outputStream());
    }

    this.applyAfterCommitHandler(request, response);
}
 
Example 8
Source File: OutputCache.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public void commit() {
    if (!committed) {
        byte[] ba = baos.toByteArray();
        ByteBuffer buffer = ByteBuffer.allocateDirect(ba.length);
        buffer.put(ba);
        buffer.flip();
        this.buffer = buffer;
        out.append(ba);
        IO.close(out);
        committed = true;
    }
}
 
Example 9
Source File: Destroyable.java    From actframework with Apache License 2.0 5 votes vote down vote up
public static void destroyAll(Collection<? extends Destroyable> col, Class<? extends Annotation> scope) {
    for (Destroyable e : col) {
        if (inScope(e, scope)) {
            e.destroy();
            if (e instanceof Closeable) {
                IO.close((Closeable) e);
            }
        }
    }
}
 
Example 10
Source File: Destroyable.java    From actframework with Apache License 2.0 5 votes vote down vote up
public static void tryDestroy(Object o, Class<? extends Annotation> scope) {
    if (null == o) {
        return;
    }
    if (!inScope(o, scope)) {
        return;
    }
    if (o instanceof Destroyable) {
        ((Destroyable) o).destroy();
    }
    if (o instanceof Closeable) {
        IO.close((Closeable) o);
    }
}
 
Example 11
Source File: CliSession.java    From actframework with Apache License 2.0 5 votes vote down vote up
public void stop() {
    exit = true;
    if (null != runningThread) {
        runningThread.interrupt();
    }
    console = null;
    IO.close(socket);
}
 
Example 12
Source File: UploadFileStorageService.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws IOException {
    if (exceedThreshold) {
        IO.close(fileOutputStream);
    }
}