001package ezvcard.io.chain;
002
003import java.io.IOException;
004import java.io.InputStream;
005import java.io.Reader;
006import java.nio.file.Path;
007
008import ezvcard.Ezvcard;
009import ezvcard.io.StreamReader;
010import ezvcard.io.json.JCardReader;
011
012/*
013 Copyright (c) 2012-2023, Michael Angstadt
014 All rights reserved.
015
016 Redistribution and use in source and binary forms, with or without
017 modification, are permitted provided that the following conditions are met: 
018
019 1. Redistributions of source code must retain the above copyright notice, this
020 list of conditions and the following disclaimer. 
021 2. Redistributions in binary form must reproduce the above copyright notice,
022 this list of conditions and the following disclaimer in the documentation
023 and/or other materials provided with the distribution. 
024
025 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
026 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
027 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
028 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
029 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
031 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
032 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
033 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
034 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
035 */
036
037/**
038 * Chainer class for parsing jCards (JSON-encoded vCards).
039 * @see Ezvcard#parseJson(InputStream)
040 * @see Ezvcard#parseJson(Path)
041 * @see Ezvcard#parseJson(Reader)
042 * @author Michael Angstadt
043 */
044public class ChainingJsonParser<T extends ChainingJsonParser<?>> extends ChainingParser<T> {
045        public ChainingJsonParser(String string) {
046                super(string);
047        }
048
049        public ChainingJsonParser(InputStream in) {
050                super(in);
051        }
052
053        public ChainingJsonParser(Reader reader) {
054                super(reader);
055        }
056
057        public ChainingJsonParser(Path file) {
058                super(file);
059        }
060
061        @Override
062        StreamReader constructReader() throws IOException {
063                if (string != null) {
064                        return new JCardReader(string);
065                }
066                if (in != null) {
067                        return new JCardReader(in);
068                }
069                if (reader != null) {
070                        return new JCardReader(reader);
071                }
072                return new JCardReader(file);
073        }
074}