Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2020 ActiveJ LLC.
*
* 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 io.activej.fs;
import io.activej.async.function.AsyncSupplier;
import io.activej.bytebuf.ByteBuf;
import io.activej.common.collection.Try;
import io.activej.common.tuple.Tuple2;
import io.activej.csp.ChannelConsumer;
import io.activej.csp.ChannelSupplier;
import io.activej.fs.exception.FsBatchException;
import io.activej.fs.exception.FsScalarException;
import io.activej.promise.Promise;
import io.activej.promise.Promises;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Stream;
import static io.activej.common.Checks.checkArgument;
import static io.activej.common.collection.CollectionUtils.isBijection;
import static java.util.stream.Collectors.*;
/**
* A file system that allows to mount several {@link ActiveFs} implementations to correspond to different filenames.
*
* Inherits the most strict limitations of all the mounted file systems implementations and root file system.
*/
final class MountingActiveFs implements ActiveFs {
private final ActiveFs root;
private final Map mounts;
MountingActiveFs(ActiveFs root, Map mounts) {
this.root = root;
this.mounts = mounts;
}
private ActiveFs findMount(String filename) {
int idx = filename.lastIndexOf('/');
while (idx != -1) {
String path = filename.substring(0, idx);
ActiveFs mount = mounts.get(path);
if (mount != null) {
return mount;
}
idx = filename.lastIndexOf('/', idx - 1);
}
return root;
}
@Override
public Promise> upload(@NotNull String name) {
return findMount(name).upload(name);
}
@Override
public Promise> upload(@NotNull String name, long size) {
return findMount(name).upload(name, size);
}
@Override
public Promise> append(@NotNull String name, long offset) {
return findMount(name).append(name, offset);
}
@Override
public Promise> download(@NotNull String name, long offset, long limit) {
return findMount(name).download(name, offset, limit);
}
@Override
public Promise