ファイル読み込み<br>

以下２種類に対応
<ol>
<li>キャッシュ時のディレクトリからFileの読み込む場合</li>
<li>キャッシュなしで クラスパス内のリソース(jarファイル内も含む)を読み込む場合</li>
</ol>

@param reader リーダ
@return SQL文を読み込み 文末のSQLコマンド分割文字(; または / )を除いた文字列を返す
@throws IOException
190218
private String read(final BufferedReader reader) throws IOException {
		StringBuilder sqlBuilder = new StringBuilder();
		try {
			for (String line : reader.lines().toArray(String[]::new)) {
				sqlBuilder.append(line).append(System.lineSeparator());
			}
		} finally {
			if (reader != null) {
				reader.close();
			}
		}

		return sqlBuilder.toString();
	}
896148
public static String read(Reader reader) {
        StringWriter writer = new StringWriter();
        try {
            char[] buffer = new char[DEFAULT_BUFFER_SIZE];
            int n;
            while (-1 != (n = reader.read(buffer))) {
                writer.write(buffer, 0, n);
            }

            return writer.toString();
        } catch (IOException ex) {
            throw new IllegalStateException("read error", ex);
        }
    }
707106
public static MtasConfiguration readConfiguration(InputStream reader)
      throws IOException {
    MtasConfiguration currentConfig = null;
    // parse xml
    XMLInputFactory factory = XMLInputFactory.newInstance();
    try {
      XMLStreamReader streamReader = factory.createXMLStreamReader(reader);
      QName qname;
      try {
        int event = streamReader.getEventType();
        while (true) {
          switch (event) {
          case XMLStreamConstants.START_DOCUMENT:
            if (!streamReader.getCharacterEncodingScheme().equals("UTF-8")) {
              throw new IOException("XML not UTF-8 encoded");
            }
            break;
          case XMLStreamConstants.END_DOCUMENT:
          case XMLStreamConstants.SPACE:
            break;
          case XMLStreamConstants.START_ELEMENT:
            // get data
            qname = streamReader.getName();
            if (currentConfig == null) {
              if (qname.getLocalPart().equals("mtas")) {
                currentConfig = new MtasConfiguration();
              } else {
                throw new IOException("no Mtas Configuration");
              }
            } else {
              MtasConfiguration parentConfig = currentConfig;
              currentConfig = new MtasConfiguration();
              parentConfig.children.add(currentConfig);
              currentConfig.parent = parentConfig;
              currentConfig.name = qname.getLocalPart();
              for (int i = 0; i < streamReader.getAttributeCount(); i++) {
                currentConfig.attributes.put(
                    streamReader.getAttributeLocalName(i),
                    streamReader.getAttributeValue(i));
              }
            }
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (currentConfig.parent == null) {
              return currentConfig;
            } else {
              currentConfig = currentConfig.parent;
            }
            break;
          case XMLStreamConstants.CHARACTERS:
            break;
          }
          if (!streamReader.hasNext()) {
            break;
          }
          event = streamReader.next();
        }
      } finally {
        streamReader.close();
      }
    } catch (XMLStreamException e) {
      log.debug(e);
    }
    return null;
  }
409890
public Reader openReader() throws FetchException {
        try {
            return getInternalClobForFetch().getCharacterStream();
        } catch (SQLException e) {
            throw mRepo.toFetchException(e);
        }
    }
382145
protected Reader getNextInputReader() throws IOException {
		if (iter == null) {
			return null;
		}
		if (!iter.hasNext()) {
			return null;
		}
		Object o = iter.next();
		if (o instanceof Reader) {
			return (Reader)o;
		} else if (o instanceof InputStream) {
			return new InputStreamReader((InputStream)o, "UTF-8"); //$NON-NLS-1$
		}
		return new StringReader(o.toString());
	}
1361730
private boolean executeCommand(final LineReader reader) throws Exception {
		String prompt = new AttributedStringBuilder()
				.style(AttributedStyle.BOLD.foreground(AttributedStyle.GREEN))
				.ansiAppend("uroborosql")
				.style(AttributedStyle.DEFAULT)
				.append(" > ")
				.toAnsi();
		String line = reader.readLine(prompt);
		if (line == null || line.isEmpty()) {
			// 空なら何もせずにループ
			return true;
		}

		String[] parts = line.split("\\s+");
		Optional<ReplCommand> command = commands.stream().filter(c -> c.is(parts[0])).findFirst();
		if (command.isPresent()) {
			return command.get().execute(reader, parts, sqlConfig, props);
		} else {
			showHelp(reader.getTerminal());
			return true;
		}
	}
1278830
public Object parse(Reader reader) {
        Object content;

        JsonLexer lexer = new JsonLexer(reader);

        JsonToken token = lexer.nextToken();
        if (token.getType() == OPEN_CURLY) {
            content = parseObject(lexer);
        } else if (token.getType() == OPEN_BRACKET) {
            content = parseArray(lexer);
        } else {
            throw new JsonException(
                    "A JSON payload should start with " + OPEN_CURLY.getLabel() +
                            " or " + OPEN_BRACKET.getLabel() + ".\n" +
                            "Instead, '" + token.getText() + "' was found " +
                            "on line: " + token.getStartLine() + ", " +
                            "column: " + token.getStartColumn()
            );
        }

        return content;
    }
789721
public static NaaccrDictionary readDictionary(Reader reader) throws IOException {
        try {
            NaaccrDictionary dictionary = (NaaccrDictionary)instanciateXStream().fromXML(reader);

            // default value for specifications
            if (dictionary.getSpecificationVersion() == null)
                dictionary.setSpecificationVersion(SpecificationVersion.SPEC_1_0);

            // default value for record types
            if (dictionary.getItems() != null)
                for (NaaccrDictionaryItem item : dictionary.getItems())
                    if (item.getRecordTypes() == null)
                        item.setRecordTypes(NaaccrFormat.ALL_RECORD_TYPES);

            // let's not validate the internal dictionaries, we know they are valid
            String uri = dictionary.getDictionaryUri();
            if (uri == null || uri.trim().isEmpty())
                throw new IOException("'dictionaryUri' attribute is required");
            else if (!BASE_DICTIONARY_URI_PATTERN.matcher(uri).matches() && !DEFAULT_USER_DICTIONARY_URI_PATTERN.matcher(uri).matches()) {
                List<String> errors = validateUserDictionary(dictionary);
                if (!errors.isEmpty())
                    throw new IOException(errors.get(0));
            }

            return dictionary;
        }
        catch (XStreamException ex) {
            throw new IOException("Unable to read dictionary", ex);
        }
    }
1218501
public static String reader2String(Reader source) throws IOException {
		char[] cbuf = new char[65535];
		StringBuffer stringbuf = new StringBuffer();

		int count = 0;
		while ((count = source.read(cbuf, 0, 65535)) != -1) {
			stringbuf.append(cbuf, 0, count);
		}

		return stringbuf.toString();
	}
763545
public static String getSqlFile(String fileName) {
		String file = "/jk/sql/".concat(fileName);
		logger.debug("Loading sql file: ", file);
		return readFile(file);
	}
406343
public static String readFully(Reader reader) throws IOException {
        try {
            StringWriter writer = new StringWriter();
            char[] buffer = new char[1024];
            int count;
            while ((count = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, count);
            }
            return writer.toString();
        } finally {
            reader.close();
        }
    }
58472
private Pair<Reader, ColumnType[]> getReaderAndColumnTypes(FixedWidthReadOptions options) throws IOException {
        ColumnType[] types = options.columnTypes();
        byte[] bytesCache = null;

        if (types == null) {
            Reader reader = options.source().createReader(bytesCache);
            if (options.source().file() == null) {
                bytesCache = CharStreams.toString(reader).getBytes();
                // create a new reader since we just exhausted the existing one
                reader = options.source().createReader(bytesCache);
            }
            types = detectColumnTypes(reader, options);
        }

        return Pair.create(options.source().createReader(bytesCache), types);
    }
365780
public Metadata readMetadata(Reader reader) {
    LineCounter lineCounter = new LineCounter("fromString", StandardCharsets.UTF_16);
    FileHashComputer fileHashComputer = new FileHashComputer("fromString");
    LineOffsetCounter lineOffsetCounter = new LineOffsetCounter();
    CharHandler[] handlers = {lineCounter, fileHashComputer, lineOffsetCounter};

    try {
      read(reader, handlers);
    } catch (IOException e) {
      throw new IllegalStateException("Should never occur", e);
    }
    return new Metadata(lineCounter.lines(), lineCounter.nonBlankLines(), fileHashComputer.getHash(), lineOffsetCounter.getOriginalLineStartOffsets(),
      lineOffsetCounter.getOriginalLineEndOffsets(),
      lineOffsetCounter.getLastValidOffset());
  }
512413
public static <T> T load(Reader reader ) {
		Yaml yaml = createYmlObject();

		Map<String,Object> data = (Map<String, Object>) yaml.load(reader);

		try {
			reader.close();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}

		return load(data);
	}
120266
private static Map<String, Object> readerToMap(JsonReader reader) throws IOException {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    reader.beginObject();
    while (reader.hasNext()) {
      map.put(reader.nextName(), readValue(reader));
    }
    reader.endObject();
    return map;
  }
306634
public static String readerToString(Reader reader) {
		try {
			StringBuilder sb = new StringBuilder();
			char[] buf = new char[1024];
			int numRead = 0;
			while ((numRead = reader.read(buf)) != -1) {
				sb.append(buf, 0, numRead);
			}
			return sb.toString();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}

	}
478516
public static String readTextStream(Reader reader) throws IOException
    {
        char[] buffer=new char[5000];
        Writer stringWriter=new StringWriter();
        int read=-1;
        try
        {
            do
            {
                //read next buffer
                read=reader.read(buffer);
                
                if(read!=-1)
                {
                    //write to string writer
                    stringWriter.write(buffer,0,read);
                }
            }while(read!=-1);
        }
        finally
        {
            //close streams
            IOHelper.closeResource(reader);
        }
        
        //get text
        String text=stringWriter.toString();
        
        return text;
    }