use of java.io.UncheckedIOException in project authlib-injector by to2mbn.
the class DeprecatedApiHttpd method queryCharacterUUID.
private Optional<String> queryCharacterUUID(String username) throws UncheckedIOException, JSONException {
String responseText;
try {
responseText = asString(postURL(configuration.getApiRoot() + "api/profiles/minecraft", CONTENT_TYPE_JSON, new JSONArray(new String[] { username }).toString().getBytes(UTF_8)));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
debug("[httpd] query uuid of username {0}, response: {1}", username, responseText);
JSONArray response = new JSONArray(responseText);
if (response.length() == 0) {
return empty();
} else if (response.length() == 1) {
return of(response.getJSONObject(0).getString("id"));
} else {
throw new JSONException("Unexpected response length");
}
}
use of java.io.UncheckedIOException in project loc-framework by lord-of-code.
the class LocSpringBootVFS method preserveSubpackageName.
private static String preserveSubpackageName(final Resource resource, final String rootPath) {
try {
final String uriStr = resource.getURI().toString();
final int start = uriStr.indexOf(rootPath);
return uriStr.substring(start);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of java.io.UncheckedIOException in project sis by apache.
the class CompoundFormat method format.
/**
* Writes a textual representation of the specified object in the given buffer.
* This method delegates its work to {@link #format(Object, Appendable)}, but
* without propagating {@link IOException}. The I/O exception should never
* occur since we are writing in a {@link StringBuffer}.
*
* <div class="note"><b>Note:</b>
* Strictly speaking, an {@link IOException} could still occur if a subclass overrides the above {@code format}
* method and performs some I/O operation outside the given {@link StringBuffer}. However this is not the intended
* usage of this class and implementors should avoid such unexpected I/O operation.</div>
*
* @param object the object to format.
* @param toAppendTo where to format the object.
* @param pos ignored in current implementation.
* @return the given buffer, returned for convenience.
*/
@Override
public StringBuffer format(final Object object, final StringBuffer toAppendTo, final FieldPosition pos) {
final Class<? extends T> valueType = getValueType();
ArgumentChecks.ensureCanCast("object", valueType, object);
try {
format(valueType.cast(object), toAppendTo);
} catch (IOException e) {
/*
* Should never happen when writing into a StringBuffer, unless the user
* override the format(Object, Appendable) method. We do not rethrow an
* AssertionError because of this possibility.
*/
throw new UncheckedIOException(e);
}
return toAppendTo;
}
use of java.io.UncheckedIOException in project sis by apache.
the class Store method components.
/**
* Returns all resources found in the folder given at construction time.
* Only the resources recognized by a {@link DataStore} will be included.
* This includes sub-folders. Resources are in no particular order.
*/
@Override
@SuppressWarnings("ReturnOfCollectionOrArrayField")
public synchronized Collection<Resource> components() throws DataStoreException {
if (components == null) {
final List<DataStore> resources = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(location, this)) {
for (final Path candidate : stream) {
/*
* The candidate path may be a symbolic link to a file that we have previously read.
* In such case, use the existing data store. A use case is a directory containing
* hundred of GeoTIFF files all accompanied by ".prj" files having identical content.
* (Note: those ".prj" files should be invisible since they should be identified as
* GeoTIFF auxiliary files, but current Store implementation does not know that).
*/
final Path real = candidate.toRealPath();
DataStore next = children.get(real);
if (next instanceof Store) {
// Warn about directories only.
((Store) next).sharedRepository(real);
}
if (next == null) {
/*
* The candidate file has never been read before. Try to read it now.
* If the file format is unknown (UnsupportedStorageException), we will
* check if we can open it as a child folder store before to skip it.
*/
final StorageConnector connector = new StorageConnector(candidate);
connector.setOption(OptionKey.LOCALE, locale);
connector.setOption(OptionKey.TIMEZONE, timezone);
connector.setOption(OptionKey.ENCODING, encoding);
try {
if (componentProvider == null) {
// May throw UnsupportedStorageException.
next = DataStores.open(connector);
} else if (componentProvider.probeContent(connector).isSupported()) {
// Open a file of specified format.
next = componentProvider.open(connector);
} else if (Files.isDirectory(candidate)) {
// Open a sub-directory.
next = new Store(this, connector);
} else {
// Not the format specified at construction time.
connector.closeAllExcept(null);
continue;
}
} catch (UnsupportedStorageException ex) {
if (!Files.isDirectory(candidate)) {
connector.closeAllExcept(null);
listeners.warning(Level.FINE, null, ex);
continue;
}
next = new Store(this, connector);
} catch (DataStoreException ex) {
try {
connector.closeAllExcept(null);
} catch (DataStoreException s) {
ex.addSuppressed(s);
}
throw ex;
}
/*
* At this point we got the data store. It could happen that a store for
* the same file has been added concurrently, so we need to check again.
*/
final DataStore existing = children.putIfAbsent(real, next);
if (existing != null) {
next.close();
next = existing;
if (next instanceof Store) {
// Warn about directories only.
((Store) next).sharedRepository(real);
}
}
}
resources.add(next);
}
} catch (DirectoryIteratorException | UncheckedIOException ex) {
// The cause is an IOException (no other type allowed).
throw new DataStoreException(canNotRead(), ex.getCause());
} catch (IOException ex) {
throw new DataStoreException(canNotRead(), ex);
} catch (BackingStoreException ex) {
throw ex.unwrapOrRethrow(DataStoreException.class);
}
components = UnmodifiableArrayList.wrap(resources.toArray(new Resource[resources.size()]));
}
// Safe because unmodifiable list.
return components;
}
use of java.io.UncheckedIOException in project sis by apache.
the class AbstractOperation method toString.
/**
* Returns a string representation of this operation.
* The returned string is for debugging purpose and may change in any future SIS version.
*
* @return a string representation of this operation for debugging purpose.
*/
@Debug
@Override
public String toString() {
final StringBuilder buffer = new StringBuilder(40).append(Classes.getShortClassName(this)).append('[');
final GenericName name = getName();
if (name != null) {
buffer.append('“');
}
buffer.append(name);
if (name != null) {
buffer.append('”');
}
final AbstractIdentifiedType result = getResult();
if (result != null) {
final Object type;
if (result instanceof DefaultAttributeType<?>) {
type = Classes.getShortName(((DefaultAttributeType<?>) result).getValueClass());
} else {
type = result.getName();
}
buffer.append(" : ").append(type);
}
try {
formatResultFormula(buffer.append("] = "));
} catch (IOException e) {
// Should never happen since we write in a StringBuilder.
throw new UncheckedIOException(e);
}
return buffer.toString();
}
Aggregations