/** * Reads a single character from this reader and returns it as an integer * with the two higher-order bytes set to 0. Returns -1 if the end of the * reader has been reached. The byte value is either obtained from * converting bytes in this reader's buffer or by first filling the buffer * from the source InputStream and then reading from the buffer. * * @return the character read or -1 if the end of the reader has been * reached. * @throws IOException * if this reader is closed or some other I/O error occurs. */ @Override public int read() throws IOException { synchronized (lock) { if (!isOpen()) { throw new IOException("InputStreamReader is closed."); } char buf[] = new char[4]; return read(buf, 0, 4) != -1 ? Character.codePointAt(buf, 0) : -1; } }
void setInput(final InputStream in) throws IOException { this.escapeTimeout = Configuration.getLong(JLINE_ESC_TIMEOUT, 100); boolean nonBlockingEnabled = escapeTimeout > 0L && terminal.isSupported() && in != null; /* * If we had a non-blocking thread already going, then shut it down * and start a new one. */ if (this.in != null) { this.in.shutdown(); } final InputStream wrapped = terminal.wrapInIfNeeded( in ); this.in = new NonBlockingInputStream(wrapped, nonBlockingEnabled); this.reader = new InputStreamReader( this.in, encoding ); }
/** * Returns the name of the encoding used to convert bytes into characters. * The value {@code null} is returned if this reader has been closed. * * @return the name of the character converter or {@code null} if this * reader is closed. */ public String getEncoding() { if (!isOpen()) { return null; } return decoder.charset().name(); }
public SystemIoTransport() { reader = new BufferedReader(new InputStreamReader(System.in)); }
public int read(char[] buf, int offset, int length) throws IOException { synchronized (lock) { if (!isOpen()) { throw new IOException("InputStreamReader is closed.");
String externalForm = format("jar:%s!/%s%s", path.toExternalForm(), EXTENSION_PREFIX, type.getName()); try (InputStreamReader inputStream = new InputStreamReader(new URL(externalForm).openStream())) { final LineReader reader = new LineReader(inputStream); modulesNames.add(reader.readLine());
/** * Reads a single character from this reader and returns it as an integer * with the two higher-order bytes set to 0. Returns -1 if the end of the * reader has been reached. The byte value is either obtained from * converting bytes in this reader's buffer or by first filling the buffer * from the source InputStream and then reading from the buffer. * * @return the character read or -1 if the end of the reader has been * reached. * @throws IOException * if this reader is closed or some other I/O error occurs. */ @Override public int read() throws IOException { synchronized (lock) { if (!isOpen()) { throw new IOException("InputStreamReader is closed."); } char buf[] = new char[4]; return read(buf, 0, 4) != -1 ? Character.codePointAt(buf, 0) : -1; } }
/** * Returns the name of the encoding used to convert bytes into characters. * The value {@code null} is returned if this reader has been closed. * * @return the name of the character converter or {@code null} if this * reader is closed. */ public String getEncoding() { if (!isOpen()) { return null; } return decoder.charset().name(); }
@Override public <T> Optional<ExtensionLookup> findExtension(ExtensionResolver<T> resolver, Class<T> type) throws IOException, ClassNotFoundException { final Set<String> resources = reflections.getResources(compile(quote(type.getName()))).stream() .filter(r -> r.startsWith(EXTENSION_PREFIX)).collect(toSet()); if (resources.isEmpty()) { return empty(); } final String extensionDescriptor = resources.iterator().next(); final LineReader reader = new LineReader(new InputStreamReader( classLoader.getResourceAsStream(extensionDescriptor))); final String implClassName = reader.readLine(); if (implClassName != null) { final Class<?> implClass = classLoader.loadClass(implClassName); if (type.isAssignableFrom(implClass)) { return of(resolver.asClass(implClass.asSubclass(type))); } if (Provider.class.isAssignableFrom(implClass)) { return of(resolver.asProvider((Class<Provider<? extends T>>) implClass)); } } return empty(); }
public int read(char[] buf, int offset, int length) throws IOException { synchronized (lock) { if (!isOpen()) { throw new IOException("InputStreamReader is closed.");
void setInput(final InputStream in) throws IOException { this.escapeTimeout = Configuration.getLong(JLINE_ESC_TIMEOUT, 100); boolean nonBlockingEnabled = escapeTimeout > 0L && terminal.isSupported() && in != null; /* * If we had a non-blocking thread already going, then shut it down * and start a new one. */ if (this.in != null) { this.in.shutdown(); } final InputStream wrapped = terminal.wrapInIfNeeded( in ); this.in = new NonBlockingInputStream(wrapped, nonBlockingEnabled); this.reader = new InputStreamReader( this.in, encoding ); }