All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ursaj.hfs.tools.HfsDefaultStorage Maven / Gradle / Ivy

/**
 * Copyright (C) 2011 UrsaJ Ltd (http://ursaj.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ursaj.hfs.tools;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.UUID;

import com.ursaj.hfs.Consumer;
import com.ursaj.hfs.client.HfsClient;
import com.ursaj.hfs.client.HfsFactory;

/** HFS client-based storage to persist binary content. */
public class HfsDefaultStorage implements HfsStorage {
    /** HFS client name to work with. */
    private final String clientName;

    /**
     * Constructs content storage.
     *
     * @param clientName HFS client name to work with.
     */
    public HfsDefaultStorage(String clientName) {
        this.clientName = clientName;
    }

    @Override
    public InputStream read(UUID fileId) throws IOException {
        return new URL(getClient().createPublishUri(fileId, null)).openStream();
    }

    @Override
    public UUID write(Consumer writer) throws IOException {
        throw new UnsupportedOperationException("Direct upload operation is not supported.");
    }

    /**
     * Return a HFS client this storage works with.
     *
     * @return HFS client instance.
     */
    protected HfsClient getClient() {
        return HfsFactory.getClient(clientName);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy