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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations