View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.commons.geometry.examples.io.threed;
    18
    19  import java.io.File;
    20  import java.io.InputStream;
    21  import java.io.OutputStream;
    22
    23  import org.apache.commons.geometry.core.precision.DoublePrecisionContext;
    24  import org.apache.commons.geometry.euclidean.threed.BoundarySource3D;
    25
    26  /** Interface for classes that handle reading and writing of 3D model files types.
    27   * For convenience and better compatibility with streams and functional programming,
    28   * all IO methods throw {@link java.io.UncheckedIOException} instead of {@link java.io.IOException}.
    29   *
    30   * <p>Implementations of this interface are expected to be thread-safe.</p>
    31   */
    32  public interface ModelIOHandler {
    33
    34      /** Return true if this instance handles 3D model files of the given type.
    35       * @param type type 3D model type, indicated by file extension
    36       * @return true if this instance can handle the 3D model file type
    37       */
    38      boolean handlesType(String type);
    39
    40      /** Read a 3D model represented as a {@link BoundarySource3D} from the given file.
    41       * @param type the model file type
    42       * @param in file to read
    43       * @param precision precision context to use in model construction
    44       * @return a 3D model represented as a boundary source
    45       * @throws java.io.UncheckedIOException if an IO operation fails
    46       * @throws IllegalArgumentException if the file type is not supported
    47       */
    48      BoundarySource3D read(String type, File in, DoublePrecisionContext precision);
    49
    50      /** Read a 3D model represented as a {@link BoundarySource3D} from the given input stream.
    51       * The input stream is closed before method return.
    52       * @param type the model input type
    53       * @param in input stream
    54       * @param precision precision context to use in model construction
    55       * @return a 3D model represented as a boundary source
    56       * @throws java.io.UncheckedIOException if an IO operation fails
    57       * @throws IllegalArgumentException if the file type is not supported
    58       */
    59      BoundarySource3D read(String type, InputStream in, DoublePrecisionContext precision);
    60
    61      /** Write the model to the file using the specified file type.
    62       * @param model model to write
    63       * @param type the model file type
    64       * @param out output file
    65       * @throws java.io.UncheckedIOException if an IO operation fails
    66       * @throws IllegalArgumentException if the file type is not supported
    67       */
    68      void write(BoundarySource3D model, String type, File out);
    69
    70      /** Write the model to the given output stream, using the specified model type.
    71       * The output stream is closed before method return.
    72       * @param model model to write
    73       * @param type the model file type
    74       * @param out output stream
    75       * @throws java.io.UncheckedIOException if an IO operation fails
    76       * @throws IllegalArgumentException if the file type is not supported
    77       */
    78      void write(BoundarySource3D model, String type, OutputStream out);
    79  }