Search in sources :

Example 81 with UncheckedIOException

use of java.io.UncheckedIOException in project sis by apache.

the class Store method write.

/**
 * Replaces the content of this GPX file by the given metadata and features.
 *
 * @param  metadata  the metadata to write, or {@code null} if none.
 * @param  features  the features to write, or {@code null} if none.
 * @throws ConcurrentReadException if the {@code features} stream was provided by this data store.
 * @throws DataStoreException if an error occurred while writing the data.
 */
public synchronized void write(final Metadata metadata, final Stream<? extends AbstractFeature> features) throws DataStoreException {
    try {
        /*
             * If we created a reader for reading metadata, we need to close that reader now otherwise the call
             * to 'new Writer(…)' will fail.  Note that if that reader was in use by someone else, the 'reader'
             * field would be null and the 'new Writer(…)' call should detect that a reader is in use somewhere.
             */
        final Reader r = reader;
        if (r != null) {
            reader = null;
            r.close();
        }
        /*
             * Get the writer if no read or other write operation is in progress, then write the data.
             */
        try (Writer writer = new Writer(this, org.apache.sis.internal.storage.gpx.Metadata.castOrCopy(metadata, locale))) {
            writer.writeStartDocument();
            if (features != null) {
                features.forEachOrdered(writer);
            }
            writer.writeEndDocument();
        }
    } catch (BackingStoreException e) {
        final Throwable cause = e.getCause();
        if (cause instanceof DataStoreException) {
            throw (DataStoreException) cause;
        }
        throw new DataStoreException(e.getLocalizedMessage(), cause);
    } catch (Exception e) {
        if (e instanceof UncheckedIOException) {
            e = ((UncheckedIOException) e).getCause();
        }
        throw new DataStoreException(e);
    }
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) BackingStoreException(org.apache.sis.util.collection.BackingStoreException) UncheckedIOException(java.io.UncheckedIOException) URISyntaxException(java.net.URISyntaxException) IllegalNameException(org.apache.sis.storage.IllegalNameException) DataStoreContentException(org.apache.sis.storage.DataStoreContentException) DataStoreException(org.apache.sis.storage.DataStoreException) BackingStoreException(org.apache.sis.util.collection.BackingStoreException) UncheckedIOException(java.io.UncheckedIOException) ConcurrentReadException(org.apache.sis.storage.ConcurrentReadException) FactoryException(org.opengis.util.FactoryException)

Example 82 with UncheckedIOException

use of java.io.UncheckedIOException in project JavaSDK by OpenGamma.

the class InvokerMarginClient method createCalculation.

@Override
public String createCalculation(Ccp ccp, MarginCalcRequest calcRequest) {
    String text = JodaBeanSer.COMPACT.jsonWriter().write(calcRequest, false);
    RequestBody body = RequestBody.create(MEDIA_JSON, text);
    Request request = new Request.Builder().url(invoker.getServiceUrl().resolve("margin/v3/ccps/" + ccp.name().toLowerCase(Locale.ENGLISH) + "/calculations")).post(body).header("Content-Type", MEDIA_JSON.toString()).header("Accept", MEDIA_JSON.toString()).build();
    try (Response response = invoker.getHttpClient().newCall(request).execute()) {
        if (response.code() != 202) {
            throw parseError(CREATE_CALCULATION, response);
        }
        String location = response.header(LOCATION);
        return location.substring(location.lastIndexOf('/') + 1);
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RequestBody(okhttp3.RequestBody)

Example 83 with UncheckedIOException

use of java.io.UncheckedIOException in project core-ng-project by neowu.

the class RedisHashImpl method del.

@Override
public boolean del(String key, String... fields) {
    StopWatch watch = new StopWatch();
    PoolItem<RedisConnection> item = redis.pool.borrowItem();
    try {
        RedisConnection connection = item.resource;
        connection.write(HDEL, encode(key, fields));
        return connection.readLong() >= 1;
    } catch (IOException e) {
        item.broken = true;
        throw new UncheckedIOException(e);
    } finally {
        redis.pool.returnItem(item);
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("redis", elapsedTime, 0, fields.length);
        logger.debug("hdel, key={}, fields={}, elapsedTime={}", key, fields, elapsedTime);
        redis.checkSlowOperation(elapsedTime);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch)

Example 84 with UncheckedIOException

use of java.io.UncheckedIOException in project core-ng-project by neowu.

the class RedisImpl method multiGetBytes.

public Map<String, byte[]> multiGetBytes(String... keys) {
    StopWatch watch = new StopWatch();
    PoolItem<RedisConnection> item = pool.borrowItem();
    try {
        RedisConnection connection = item.resource;
        byte[][] arguments = new byte[keys.length][];
        for (int i = 0; i < keys.length; i++) {
            arguments[i] = encode(keys[i]);
        }
        Map<String, byte[]> values = Maps.newHashMapWithExpectedSize(keys.length);
        connection.write(Protocol.Command.MGET, arguments);
        Object[] response = connection.readArray();
        for (int i = 0; i < response.length; i++) {
            byte[] value = (byte[]) response[i];
            if (value != null)
                values.put(keys[i], value);
        }
        return values;
    } catch (IOException e) {
        item.broken = true;
        throw new UncheckedIOException(e);
    } finally {
        pool.returnItem(item);
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("redis", elapsedTime, keys.length, 0);
        logger.debug("mget, keys={}, elapsedTime={}", keys, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch)

Example 85 with UncheckedIOException

use of java.io.UncheckedIOException in project core-ng-project by neowu.

the class RedisImpl method multiSet.

@Override
public void multiSet(Map<String, String> values) {
    StopWatch watch = new StopWatch();
    PoolItem<RedisConnection> item = pool.borrowItem();
    try {
        RedisConnection connection = item.resource;
        connection.write(Protocol.Command.MSET, encode(values));
        connection.readSimpleString();
    } catch (IOException e) {
        item.broken = true;
        throw new UncheckedIOException(e);
    } finally {
        pool.returnItem(item);
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("redis", elapsedTime, 0, values.size());
        logger.debug("mset, values={}, elapsedTime={}", values, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StopWatch(core.framework.util.StopWatch)

Aggregations

UncheckedIOException (java.io.UncheckedIOException)826 IOException (java.io.IOException)786 File (java.io.File)109 Path (java.nio.file.Path)106 ArrayList (java.util.ArrayList)70 InputStream (java.io.InputStream)58 Map (java.util.Map)58 List (java.util.List)55 HashMap (java.util.HashMap)44 Test (org.junit.Test)38 Files (java.nio.file.Files)37 Collectors (java.util.stream.Collectors)37 Stream (java.util.stream.Stream)31 URL (java.net.URL)29 StringWriter (java.io.StringWriter)27 CursorContext (org.neo4j.io.pagecache.context.CursorContext)25 FileInputStream (java.io.FileInputStream)23 HashSet (java.util.HashSet)23 PageCursor (org.neo4j.io.pagecache.PageCursor)22 Optional (java.util.Optional)21