Tabnine Logo
InputStreamReader.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
java.io.InputStreamReader
constructor

Best Java code snippets using java.io.InputStreamReader.<init> (Showing top 20 results out of 109,971)

Refine searchRefine arrow

  • BufferedReader.readLine
  • BufferedReader.<init>
  • PrintStream.println
  • BufferedReader.close
  • FileInputStream.<init>
  • URL.<init>
canonical example by Tabnine

public void postRequest(String urlStr, String jsonBodyStr) throws IOException {
  URL url = new URL(urlStr);
  HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  httpURLConnection.setDoOutput(true);
  httpURLConnection.setRequestMethod("POST");
  httpURLConnection.setRequestProperty("Content-Type", "application/json");
  try (OutputStream outputStream = httpURLConnection.getOutputStream()) { 
   outputStream.write(jsonBodyStr.getBytes());
   outputStream.flush();
  }
  if (httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
    try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()))) {
      String line;
      while ((line = bufferedReader.readLine()) != null) {
        // ... do something with line
      }
    }
  } else {
    // ... do something with unsuccessful response
  }
}
canonical example by Tabnine

public void readAllLines(InputStream in) throws IOException {
 try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in))) {
  String line;
  while ((line = bufferedReader.readLine()) != null) {
   // ... do something with line
  }
 }
}
origin: jenkinsci/jenkins

/**
 * Read the first line of the given stream, close it, and return that line.
 *
 * @param encoding
 *      If null, use the platform default encoding.
 * @since 1.422
 */
public static String readFirstLine(InputStream is, String encoding) throws IOException {
  try (BufferedReader reader = new BufferedReader(
      encoding == null ? new InputStreamReader(is) : new InputStreamReader(is, encoding))) {
    return reader.readLine();
  }
}
origin: google/guava

/**
 * Returns a buffered reader that reads from a file using the given character set.
 *
 * <p><b>{@link java.nio.file.Path} equivalent:</b> {@link
 * java.nio.file.Files#newBufferedReader(java.nio.file.Path, Charset)}.
 *
 * @param file the file to read from
 * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for
 *     helpful predefined constants
 * @return the buffered reader
 */
public static BufferedReader newReader(File file, Charset charset) throws FileNotFoundException {
 checkNotNull(file);
 checkNotNull(charset);
 return new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
}
origin: libgdx/libgdx

/** Returns a buffered reader for reading this file as characters.
 * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */
public BufferedReader reader (int bufferSize) {
  return new BufferedReader(new InputStreamReader(read()), bufferSize);
}
origin: eugenp/tutorials

  private String bodyToString(InputStream body) throws IOException {
    StringBuilder builder = new StringBuilder();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(body, StandardCharsets.UTF_8));
    String line = bufferedReader.readLine();
    while (line != null) {
      builder.append(line).append(System.lineSeparator());
      line = bufferedReader.readLine();
    }
    bufferedReader.close();
    return builder.toString();
  }
}
origin: apache/incubator-shardingsphere

private static YamlOrchestrationMasterSlaveRuleConfiguration unmarshal(final File yamlFile) throws IOException {
  try (
      FileInputStream fileInputStream = new FileInputStream(yamlFile);
      InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8")
  ) {
    return new Yaml(new Constructor(YamlOrchestrationMasterSlaveRuleConfiguration.class)).loadAs(inputStreamReader, YamlOrchestrationMasterSlaveRuleConfiguration.class);
  }
}

origin: stackoverflow.com

 public static void main(String[] args) throws Exception {
  String google = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=";
  String search = "stackoverflow";
  String charset = "UTF-8";

  URL url = new URL(google + URLEncoder.encode(search, charset));
  Reader reader = new InputStreamReader(url.openStream(), charset);
  GoogleResults results = new Gson().fromJson(reader, GoogleResults.class);

  // Show title and URL of 1st result.
  System.out.println(results.getResponseData().getResults().get(0).getTitle());
  System.out.println(results.getResponseData().getResults().get(0).getUrl());
}
origin: apache/incubator-dubbo

/**
 * read lines.
 *
 * @param is input stream.
 * @return lines.
 * @throws IOException
 */
public static String[] readLines(InputStream is) throws IOException {
  List<String> lines = new ArrayList<String>();
  BufferedReader reader = new BufferedReader(new InputStreamReader(is));
  try {
    String line;
    while ((line = reader.readLine()) != null) {
      lines.add(line);
    }
    return lines.toArray(new String[0]);
  } finally {
    reader.close();
  }
}
origin: neo4j/neo4j

public static BufferedReader newBufferedFileReader( File file, Charset charset ) throws FileNotFoundException
{
  return new BufferedReader( new InputStreamReader( new FileInputStream( file ), charset ) );
}
origin: stackoverflow.com

 String contentType = connection.getHeaderField("Content-Type");
String charset = null;

for (String param : contentType.replace(" ", "").split(";")) {
  if (param.startsWith("charset=")) {
    charset = param.split("=", 2)[1];
    break;
  }
}

if (charset != null) {
  try (BufferedReader reader = new BufferedReader(new InputStreamReader(response, charset))) {
    for (String line; (line = reader.readLine()) != null;) {
      // ... System.out.println(line) ?
    }
  }
} else {
  // It's likely binary content, use InputStream/OutputStream.
}
origin: stackoverflow.com

String result = new BufferedReader(new InputStreamReader(inputStream))
.lines().collect(Collectors.joining("\n"));
origin: apache/incubator-shardingsphere

private static YamlOrchestrationShardingRuleConfiguration unmarshal(final File yamlFile) throws IOException {
  try (
      FileInputStream fileInputStream = new FileInputStream(yamlFile);
      InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8")
  ) {
    return new Yaml(new Constructor(YamlOrchestrationShardingRuleConfiguration.class)).loadAs(inputStreamReader, YamlOrchestrationShardingRuleConfiguration.class);
  }
}

origin: apache/incubator-dubbo

/**
 * read lines.
 *
 * @param is input stream.
 * @return lines.
 * @throws IOException
 */
public static String[] readLines(InputStream is) throws IOException {
  List<String> lines = new ArrayList<String>();
  BufferedReader reader = new BufferedReader(new InputStreamReader(is));
  try {
    String line;
    while ((line = reader.readLine()) != null) {
      lines.add(line);
    }
    return lines.toArray(new String[0]);
  } finally {
    reader.close();
  }
}
origin: prestodb/presto

private BufferedReader createNextReader()
    throws IOException
{
  if (!files.hasNext()) {
    return null;
  }
  File file = files.next();
  FileInputStream fileInputStream = new FileInputStream(file);
  InputStream in = isGZipped(file) ? new GZIPInputStream(fileInputStream) : fileInputStream;
  return new BufferedReader(new InputStreamReader(in));
}
origin: stackoverflow.com

 String newLine = System.getProperty("line.separator");
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder result = new StringBuilder();
String line; boolean flag = false;
while ((line = reader.readLine()) != null) {
  result.append(flag? newLine: "").append(line);
  flag = true;
}
return result.toString();
origin: libgdx/libgdx

/** Returns a buffered reader for reading this file as characters.
 * @throw GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */
public BufferedReader reader (int bufferSize) {
  return new BufferedReader(new InputStreamReader(read()), bufferSize);
}
origin: apache/incubator-shardingsphere

private YamlProxyServerConfiguration loadServerConfiguration(final File yamlFile) throws IOException {
  try (
      FileInputStream fileInputStream = new FileInputStream(yamlFile);
      InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8")
  ) {
    YamlProxyServerConfiguration result = new Yaml(new Constructor(YamlProxyServerConfiguration.class)).loadAs(inputStreamReader, YamlProxyServerConfiguration.class);
    Preconditions.checkNotNull(result, "Server configuration file `%s` is invalid.", yamlFile.getName());
    Preconditions.checkState(!Strings.isNullOrEmpty(result.getAuthentication().getUsername()) || null != result.getOrchestration(), "Authority configuration is invalid.");
    return result;
  }
}

origin: Netflix/eureka

public String read(InputStream inputStream) throws IOException {
  BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
  String toReturn;
  try {
    String line = br.readLine();
    toReturn = line;
    while (line != null) {  // need to read all the buffer for a clean connection close
      line = br.readLine();
    }
    return toReturn;
  } finally {
    br.close();
  }
}
origin: stanfordnlp/CoreNLP

public TextTaggedFileReader(TaggedFileRecord record) {
 filename = record.file;
 try {
  reader = new BufferedReader(new InputStreamReader
                (new FileInputStream(filename), 
                 record.encoding));
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 tagSeparator = record.tagSeparator;
 primeNext();
}
java.ioInputStreamReader<init>

Javadoc

Constructs a new InputStreamReader on the InputStream in. This constructor sets the character converter to the encoding specified in the "file.encoding" property and falls back to ISO 8859_1 (ISO-Latin-1) if the property doesn't exist.

Popular methods of InputStreamReader

  • close
    Close the stream.
  • read
    Reads characters into a portion of an array.
  • getEncoding
    Returns the name of the character encoding being used by this stream. If the encoding has an histori
  • ready
    Tells whether this stream is ready to be read. An InputStreamReader is ready if its input buffer is
  • skip
  • markSupported
  • mark
  • reset
  • isOpen

Popular in Java

  • Reactive rest calls using spring rest template
  • getSupportFragmentManager (FragmentActivity)
  • notifyDataSetChanged (ArrayAdapter)
  • scheduleAtFixedRate (Timer)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Collectors (java.util.stream)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now