001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.geometry.io.euclidean.threed.txt;
018
019import java.nio.charset.Charset;
020import java.nio.charset.StandardCharsets;
021
022import org.apache.commons.geometry.io.core.GeometryFormat;
023import org.apache.commons.geometry.io.core.input.GeometryInput;
024import org.apache.commons.geometry.io.core.internal.GeometryIOUtils;
025import org.apache.commons.geometry.io.euclidean.threed.AbstractBoundaryReadHandler3D;
026import org.apache.commons.geometry.io.euclidean.threed.FacetDefinitionReader;
027import org.apache.commons.geometry.io.euclidean.threed.GeometryFormat3D;
028
029/** {@link org.apache.commons.geometry.io.euclidean.threed.BoundaryReadHandler3D BoundaryReadHandler3D}
030 * implementation for the non-standard {@link GeometryFormat3D#TXT TXT}.
031 * @see TextFacetDefinitionReader
032 */
033public class TextBoundaryReadHandler3D extends AbstractBoundaryReadHandler3D {
034
035    /** Default charset for reading text input. */
036    private Charset defaultCharset = StandardCharsets.UTF_8;
037
038    /** Get the text input default charset, used if the input does not
039     * specify a charset.
040     * @return text input default charset
041     */
042    public Charset getDefaultCharset() {
043        return defaultCharset;
044    }
045
046    /** Set the text input default charset, used if the input does not
047     * specify a charset.
048     * @param defaultCharset text input default charset
049     */
050    public void setDefaultCharset(final Charset defaultCharset) {
051        this.defaultCharset = defaultCharset;
052    }
053
054    /** {@inheritDoc} */
055    @Override
056    public GeometryFormat getFormat() {
057        return GeometryFormat3D.TXT;
058    }
059
060    /** {@inheritDoc} */
061    @Override
062    public FacetDefinitionReader facetDefinitionReader(final GeometryInput in) {
063        return new TextFacetDefinitionReader(GeometryIOUtils.createBufferedReader(in, defaultCharset));
064    }
065}