Search in sources :

Example 76 with UncheckedIOException

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");
    }
}
Also used : JSONArray(org.to2mbn.authlibinjector.internal.org.json.JSONArray) JSONException(org.to2mbn.authlibinjector.internal.org.json.JSONException) UncheckedIOException(java.io.UncheckedIOException) IOUtils.asString(org.to2mbn.authlibinjector.util.IOUtils.asString) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 77 with UncheckedIOException

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);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 78 with UncheckedIOException

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;
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 79 with UncheckedIOException

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;
}
Also used : Path(java.nio.file.Path) DirectoryIteratorException(java.nio.file.DirectoryIteratorException) StorageConnector(org.apache.sis.storage.StorageConnector) DataStoreException(org.apache.sis.storage.DataStoreException) ArrayList(java.util.ArrayList) UnmodifiableArrayList(org.apache.sis.internal.util.UnmodifiableArrayList) BackingStoreException(org.apache.sis.util.collection.BackingStoreException) DataStore(org.apache.sis.storage.DataStore) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) DataStore(org.apache.sis.storage.DataStore) UnsupportedStorageException(org.apache.sis.storage.UnsupportedStorageException)

Example 80 with UncheckedIOException

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();
}
Also used : GenericName(org.opengis.util.GenericName) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Debug(org.apache.sis.util.Debug)

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