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

br.com.objectos.io.NotFoundJava7 Maven / Gradle / Ivy

/*
 * Copyright (C) 2011-2021 Objectos Software LTDA.
 *
 * 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 br.com.objectos.io;

import br.com.objectos.multirelease.Concrete;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;

@Concrete.Bridge
abstract class NotFoundJava7 extends AbstractNotFound {

  private final Path delegate;

  @Concrete.Constructor
  NotFoundJava7(File file) {
    throw new AssertionError("Should never be called");
  }

  @Concrete.Constructor
  NotFoundJava7(Path delegate) {
    this.delegate = delegate;
  }

  @Override
  public final Directory createDirectory() throws IOException {
    Files.createDirectories(delegate);

    return new Directory(delegate);
  }

  @Override
  public final void createParents() throws IOException {
    Path parent;
    parent = delegate.getParent();

    if (parent == null) {
      return;
    }

    Files.createDirectories(parent);
  }

  @Override
  public final RegularFile createRegularFile() throws IOException {
    Files.createFile(delegate);

    return new RegularFile(delegate);
  }

  @Override
  public final boolean exists() {
    return Files.exists(delegate);
  }

  @Override
  public final String getExtension() {
    return Io.getExtension(getName());
  }

  @Override
  public final String getName() {
    Path fileName;
    fileName = delegate.getFileName();

    return fileName.toString();
  }

  @Override
  public final FsObject getParent() {
    Path parent;
    parent = delegate.getParent();

    return QueryBuilderJava7.refresh(parent);
  }

  @Override
  public final OutputStream openOutputStream() throws IOException {
    return Files.newOutputStream(delegate, IoFsJava7.OPEN_CREATENEW_WRITE);
  }

  @Override
  public final FileChannel openWriteChannel() throws IOException {
    return FileChannel.open(delegate, IoFsJava7.OPEN_CREATENEW_WRITE);
  }

  @Override
  public final FsObject refresh() {
    return QueryBuilderJava7.refresh(getDelegate());
  }

  @Override
  public final File toFile() {
    return delegate.toFile();
  }

  @Override
  public final URI toUri() {
    return delegate.toUri();
  }

  @Override
  final Path getDelegate() {
    return delegate;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy