Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2011 Ursa Project LLC (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.service;
import java.util.*;
import static com.ursaj.hfs.util.HfsUtils.UUID_COMPARATOR;

In-memory service to work with stored files information (for tests or example usage).

Parameters:
<T> File information type your application works with.
public final class HfsMemoryFileService<T extends HfsFileInfoimplements HfsFileService<T> {
    
Uploaded files storage.
    private final ConcurrentNavigableMap<UUID, T> storage = new ConcurrentSkipListMap<UUID, T>();
    @Override
    public Map<UUID, T> getFiles(Set<UUIDfileIds) {
        Map<UUID, T> map = new HashMap<UUID, T>(fileIds.size(), 1.0f);
        for (UUID fileId : fileIds)
            map.put(fileId.get(fileId));
        return Collections.unmodifiableMap(map);
    }
    @Override
    public void storeFiles(Collection<T> fileInfosthrows IOException {
        for (T fileInfo : fileInfos)
            if (.putIfAbsent(fileInfo.getFileId(), fileInfo) != null)
                throw new IOException("Failed to store file information with duplicated ID: " + fileInfo.getFileId());
    }
    @Override
    public boolean collectAliveFiles(UUID fromIdConsumer<UUIDIOExceptionconsumerthrows IOException {
        for (UUID fileId : .tailMap(fromId).keySet())
            if (!consumer.offer(fileId))
                return false;
        return true;
    }
New to GrepCode? Check out our FAQ X