1 package org.metricshub.jawk.util;
2
3 /*-
4 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5 * Jawk
6 * ჻჻჻჻჻჻
7 * Copyright (C) 2006 - 2025 MetricsHub
8 * ჻჻჻჻჻჻
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU General Lesser Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
23 */
24
25 import java.io.IOException;
26 import java.io.Reader;
27
28 /**
29 * Represents one AWK-script content source.
30 * This is usually either a string,
31 * given on the command line with the first non-"-" parameter,
32 * or an "*.awk" script,
33 * given as a path with a "-f" command line switch.
34 *
35 * @author Danny Daglas
36 */
37 public class ScriptSource {
38
39 /** Constant <code>DESCRIPTION_COMMAND_LINE_SCRIPT="<command-line-supplied-script>"</code> */
40 public static final String DESCRIPTION_COMMAND_LINE_SCRIPT = "<command-line-supplied-script>";
41
42 private String description;
43 private Reader reader;
44
45 /**
46 * <p>
47 * Constructor for ScriptSource.
48 * </p>
49 *
50 * @param description a {@link java.lang.String} object
51 * @param reader a {@link java.io.Reader} object
52 */
53 public ScriptSource(String description, Reader reader) {
54 this.description = description;
55 this.reader = reader;
56 }
57
58 /**
59 * <p>
60 * Getter for the field <code>description</code>.
61 * </p>
62 *
63 * @return a {@link java.lang.String} object
64 */
65 public final String getDescription() {
66 return description;
67 }
68
69 /**
70 * Obtain the {@link Reader} serving the script contents.
71 *
72 * @return The reader which contains the script contents.
73 * @throws java.io.IOException if any.
74 */
75 public Reader getReader() throws IOException {
76 return reader;
77 }
78
79 /** {@inheritDoc} */
80 @Override
81 public String toString() {
82 return getDescription();
83 }
84 }