Search in sources :

Example 1 with ErrorResponseException

use of io.minio.errors.ErrorResponseException in project runelite by runelite.

the class CacheUploader method run.

@Override
public void run() {
    byte[] hash = Hashing.sha256().hashBytes(data).asBytes();
    String hashStr = BaseEncoding.base16().encode(hash);
    archive.setHash(hash);
    String path = new StringBuilder().append(hashStr.substring(0, 2)).append('/').append(hashStr.substring(2)).toString();
    try {
        try (InputStream in = minioClient.getObject(minioBucket, path)) {
            // already exists
            return;
        } catch (ErrorResponseException ex) {
        // doesn't exist
        }
        minioClient.putObject(minioBucket, path, new ByteArrayInputStream(data), data.length, "binary/octet-stream");
    } catch (ErrorResponseException | InsufficientDataException | InternalException | InvalidArgumentException | InvalidBucketNameException | NoResponseException | IOException | InvalidKeyException | NoSuchAlgorithmException | XmlPullParserException ex) {
        logger.warn("unable to upload data to store", ex);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InvalidBucketNameException(io.minio.errors.InvalidBucketNameException) InsufficientDataException(io.minio.errors.InsufficientDataException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) InternalException(io.minio.errors.InternalException) InvalidArgumentException(io.minio.errors.InvalidArgumentException) ByteArrayInputStream(java.io.ByteArrayInputStream) ErrorResponseException(io.minio.errors.ErrorResponseException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NoResponseException(io.minio.errors.NoResponseException)

Example 2 with ErrorResponseException

use of io.minio.errors.ErrorResponseException in project runelite by runelite.

the class CacheService method getArchive.

/**
 * retrieve archive from storage
 *
 * @param archiveEntry
 * @return
 */
public byte[] getArchive(ArchiveEntry archiveEntry) {
    String hashStr = BaseEncoding.base16().encode(archiveEntry.getHash());
    String path = new StringBuilder().append(hashStr.substring(0, 2)).append('/').append(hashStr.substring(2)).toString();
    try (InputStream in = minioClient.getObject(minioBucket, path)) {
        return ByteStreams.toByteArray(in);
    } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException | InvalidKeyException | NoResponseException | XmlPullParserException | ErrorResponseException | InternalException | InvalidArgumentException ex) {
        log.warn(null, ex);
        return null;
    }
}
Also used : InputStream(java.io.InputStream) InvalidBucketNameException(io.minio.errors.InvalidBucketNameException) InsufficientDataException(io.minio.errors.InsufficientDataException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) InternalException(io.minio.errors.InternalException) InvalidArgumentException(io.minio.errors.InvalidArgumentException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ErrorResponseException(io.minio.errors.ErrorResponseException) NoResponseException(io.minio.errors.NoResponseException)

Example 3 with ErrorResponseException

use of io.minio.errors.ErrorResponseException in project fess by codelibs.

the class AdminStorageAction method getFileItems.

public static List<Map<String, Object>> getFileItems(final String prefix) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final ArrayList<Map<String, Object>> list = new ArrayList<>();
    try {
        final MinioClient minioClient = createClient(fessConfig);
        final ListObjectsArgs args = ListObjectsArgs.builder().bucket(fessConfig.getStorageBucket()).prefix(prefix != null && prefix.length() > 0 ? prefix + "/" : prefix).recursive(false).includeUserMetadata(false).useApiVersion1(false).build();
        for (final Result<Item> result : minioClient.listObjects(args)) {
            final Map<String, Object> map = new HashMap<>();
            final Item item = result.get();
            final String objectName = item.objectName();
            map.put("id", encodeId(objectName));
            map.put("name", getName(objectName));
            map.put("hashCode", item.hashCode());
            map.put("size", item.size());
            map.put("directory", item.isDir());
            if (!item.isDir()) {
                map.put("lastModified", item.lastModified());
            }
            list.add(map);
            if (list.size() > fessConfig.getStorageMaxItemsInPageAsInteger()) {
                break;
            }
        }
    } catch (final ErrorResponseException e) {
        final String code = e.errorResponse().code();
        if ("NoSuchBucket".equals(code)) {
            final MinioClient minioClient = createClient(fessConfig);
            try {
                final MakeBucketArgs args = MakeBucketArgs.builder().bucket(fessConfig.getStorageBucket()).build();
                minioClient.makeBucket(args);
                logger.info("Created bucket: {}", fessConfig.getStorageBucket());
            } catch (final Exception e1) {
                logger.warn("Failed to create bucket: {}", fessConfig.getStorageBucket(), e1);
            }
        } else if (logger.isDebugEnabled()) {
            logger.debug("Failed to access {}", fessConfig.getStorageEndpoint(), e);
        }
    } catch (final Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to access {}", fessConfig.getStorageEndpoint(), e);
        }
    }
    return list;
}
Also used : MakeBucketArgs(io.minio.MakeBucketArgs) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StorageException(org.codelibs.fess.exception.StorageException) ErrorResponseException(io.minio.errors.ErrorResponseException) ListObjectsArgs(io.minio.ListObjectsArgs) Item(io.minio.messages.Item) MinioClient(io.minio.MinioClient) ErrorResponseException(io.minio.errors.ErrorResponseException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ErrorResponseException (io.minio.errors.ErrorResponseException)3 InsufficientDataException (io.minio.errors.InsufficientDataException)2 InternalException (io.minio.errors.InternalException)2 InvalidArgumentException (io.minio.errors.InvalidArgumentException)2 InvalidBucketNameException (io.minio.errors.InvalidBucketNameException)2 NoResponseException (io.minio.errors.NoResponseException)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 ListObjectsArgs (io.minio.ListObjectsArgs)1 MakeBucketArgs (io.minio.MakeBucketArgs)1 MinioClient (io.minio.MinioClient)1 Item (io.minio.messages.Item)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StorageException (org.codelibs.fess.exception.StorageException)1