{"id":16908687,"url":"https://github.com/williamfiset/fastjavaio","last_synced_at":"2025-10-24T17:51:27.222Z","repository":{"id":81904412,"uuid":"64015701","full_name":"williamfiset/FastJavaIO","owner":"williamfiset","description":"Very fast Java input reader. ","archived":false,"fork":false,"pushed_at":"2023-08-16T04:42:42.000Z","size":160599,"stargazers_count":113,"open_issues_count":6,"forks_count":41,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T04:35:02.008Z","etag":null,"topics":["inputreader","io","stream"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/williamfiset.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-23T12:41:47.000Z","updated_at":"2025-02-22T06:22:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"0b2382b8-f03b-495a-b24c-70a76d583669","html_url":"https://github.com/williamfiset/FastJavaIO","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/williamfiset/FastJavaIO","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamfiset%2FFastJavaIO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamfiset%2FFastJavaIO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamfiset%2FFastJavaIO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamfiset%2FFastJavaIO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/williamfiset","download_url":"https://codeload.github.com/williamfiset/FastJavaIO/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamfiset%2FFastJavaIO/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280841062,"owners_count":26400398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-24T02:00:06.418Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["inputreader","io","stream"],"created_at":"2024-10-13T18:52:30.847Z","updated_at":"2025-10-24T17:51:27.216Z","avatar_url":"https://github.com/williamfiset.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# InputReader\n\nThe InputReader provides a way to read data from an input stream (like java.util.Scanner) but many orders of magnitude faster. Below is a graph outlining the speed differences between this InputReader verses using a BufferedReader (the Java Scanner was too slow to make it on the graph). To get started using the InputReader look at the examples below on how to read various types of data from an input stream. \n\n![Graph](https://raw.githubusercontent.com/williamfiset/FastJavaIO/master/images/graph.png)\n\n### Reading from an input stream\n\nInput data can come from a variety of sources. Sometimes it comes from standard input in the form of [System.in](https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#in), other times it may come from a file we are trying to read as a [FileInputStream](https://docs.oracle.com/javase/7/docs/api/java/io/FileInputStream.html) object or even through a [Web Socket](https://docs.oracle.com/javase/7/docs/api/java/net/Socket.html#getInputStream()). For this reason, anything that extends the [InputStream](https://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html) class can be read with our InputReader. The default stream is set to be the standard input stream, but this can be changed when constructing an InputReader object:\n\n``` java\n\n// Reading from standard input\nInputReader stdinReader = new InputReader(); // Defaults to reading from System.in\nString line = stdinReader.nextLine();\n\n// Reading from a file\nFileInputStream fileStream = new FileInputStream(\"/path/to/the/file\");\nInputReader fileReader = new InputReader(fileStream);\nString line = fileReader.nextLine();\n\n// Reading from Web Socket\nSocket socket = new Socket(\"Some Machine\", port);\nInputReader socketReader = new InputReader(socket.getInputStream());\nString data = socketReader.nextString(); // Read first string\n\n```\n\n## Getting started\n\nThe first step to getting started with the InputReader is to include the **[fastjavaio.jar](https://github.com/williamfiset/FastJavaIO/releases/download/1.1/fastjavaio.jar)** to your project. If you're running your application on the command-line this can easily be done by adding the jar file to your [CLASSPATH](https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html).\n\nIf you're using a Unix like system try:\n```bash\njavac -cp .:fastjavaio.jar MyProgram.java  # Compile\njava -cp .:fastjavaio.jar MyProgram        # Run\n```\n\nIf you're using Windows try:\n```bash\njavac -cp .;fastjavaio.jar MyProgram.java # Compile\njava -cp .;fastjavaio.jar MyProgram       # Run\n```\n\nTo actually use the InputReader class within your application you need to import it from within the fastjavaio package:\n\n``` java\n// Import the InputReader class\nimport com.williamfiset.fastjavaio.InputReader;\n\npublic class InputReaderUsageExample {\n  public static void main (String[] args) throws java.io.IOException {\n    \n    // Create an InputReader object that reads data from standard input by default\n    InputReader in = new InputReader();\n    \n    // read input here...\n    \n  }\n}\n\n```\n\n## InputReader methods\n\n**ALL methods in the InputReader class must be caught or thrown** because they throw an java.io.IOException when something bad happens such as trying to read a byte value from an empty stream. See [here](https://github.com/williamfiset/FastJavaIO#examples) for detailed examples of how to use the methods outlined below.\n\n### .nextByte()\nReads a signed 8 bit integer from the input stream.\n``` java\nInputReader in = new InputReader();\nbyte byteValue = in.nextByte();\n```\n\n### .nextInt()\nReads a signed 32 bit integer from the input stream.\n``` java\nInputReader in = new InputReader();\nint intValue = in.nextInt();\n```\n\n### .nextLong()\nReads a signed 64 bit integer from the input stream.\n``` java\nInputReader in = new InputReader();\nlong longValue = in.nextLong();\n```\n\n### .nextDouble()\nReads a signed double from the input stream.\n``` java\nInputReader in = new InputReader();\ndouble doubleValue = in.nextDouble();\n```\n\n### .nextDoubleFast()\nReads a double value ~3x times faster from the input stream than the .nextDouble() method, but at the cost of accuracy. This method can only read doubles with at most 21 digits after the decimal point. Furthermore, the value being read may have an error of at most ~5*10^-16 (obtained from empirical tests) from its true value due to finite floating point number arithmetic (adding, multiplication) used to perform the quick read.\n``` java\nInputReader in = new InputReader();\ndouble doubleValue = in.nextDoubleFast();\n```\n### .nextString()\nReads a string of characters from the input stream. The delimiter separating a string of characters is set to be any ASCII value \u003c= 32, meaning any spaces, new lines, EOF characters, tabs... all of which do not count as being part of the string. If the input stream is empty null is returned.\n``` java\nInputReader in = new InputReader();\nString str = in.nextString();\n```\n\n### .nextLine()\nReads a line of characters from the input stream until a new line character is reached. The .nextLine() method includes spaces found in the input stream. If the input stream is empty a null value is returned to indicate so.\n``` java\nInputReader in = new InputReader();\nString line = in.nextLine();\n```\n\n### .nextByteArray(int n)\n\nReads n byte values into a byte array. If the specified value of n is too large and not enough bytes are found an exception is thrown.\n\n```java\nInputReader in = new InputReader();\nint bytesToRead = 16;\nbyte[] bytes = in.nextByteArray(bytesToRead);\n```\n\n### .nextIntArray(int n)\n\nReads n signed 32bit integer values into an array. If the specified value of n is too large and not enough integers are found an exception is thrown.\n\n```java\nInputReader in = new InputReader();\nint integersToRead = 16;\nint[] integers = in.nextIntArray(integersToRead);\n```\n\n### .nextLongArray(int n)\n\nReads n signed 64bit long values into an array. If the specified value of n is too large and not enough longs are found an exception is thrown.\n\n```java\nInputReader in = new InputReader();\nint longsToRead = 16;\nlong[] longs = in.nextLongArray(longsToRead);\n```\n\n### .nextDoubleArray(int n)\n\nReads n double values into an array. If the specified value of n is too large and not enough doubles are found an exception is thrown.\n\n```java\nInputReader in = new InputReader();\nint doublesToRead = 16;\ndouble[] doubles = in.nextDoubleArray(doublesToRead);\n```\n\n### .nextDoubleArrayFast(int n)\n\nQuickly reads n double values into an array using the .nextDoubleFast() method. If the specified value of n is too large and not enough doubles are found an exception is thrown.\n\n```java\nInputReader in = new InputReader();\nint doublesToRead = 16;\ndouble[] doubles = in.nextDoubleArrayFast(doublesToRead);\n```\n\n### .nextStringArray(int n)\n\nReads n space separated strings into an array. If the specified value of n is too large and not enough strings are found in the input stream an exception is thrown.\n\n```java\nInputReader in = new InputReader();\nint stringsToRead = 16;\nString[] strings = in.nextStringArray(stringsToRead);\n```\n\n**NOTE**: If you want to read data into a 1-based array instead of a 0-based array you can use the following methods exist for such a purpose:\n* nextByteArray1(int n)\n* nextIntArray1(int n)\n* nextLongArray1(int n)\n* nextDoubleArray1(int n)\n* nextDoubleArrayFast1(int n)\n* nextStringArray1(int n)\n\n## Examples\n\n#### General case\n\n``` java\n// Suppose standard input stream contains the following string we want to read:\n\"  123 3.141592    abcdef    the quick brown fox\\n jumps \\nover\\n\\n the lazy dog\"\n\nInputReader in = new InputReader();\nint intvalue = in.nextInt();       // '123'\ndouble dblvalue = in.nextDouble(); // '3.141592'\nString str = in.nextString();         // 'abcdef'\nString str2 = in.nextString();        // 'the'\nString line = in.nextLine();       // 'quick brown fox'\nString line1 = in.nextLine();      // ' jumps '\nString line2 = in.nextLine();      // 'over'\nString line3 = in.nextLine();      // ''\nString line4 = in.nextLine();      // ' the lazy dog'\nString line5 = in.nextLine();      // null\n```\n\n#### .nextByte() examples\n``` java\n// Suppose standard input stream contains the following byte values we want to read:\n\"-128 127 -1 -0 0 1 3454\"\n//                     ^ NOTE: This does NOT fit in a signed byte!\n\nInputReader in = new InputReader();\nbyte b1 = in.nextByte(); // -128\nbyte b2 = in.nextByte(); // 127\nbyte b3 = in.nextByte(); // -1\nbyte b4 = in.nextByte(); // 0\nbyte b5 = in.nextByte(); // 0\nbyte b6 = in.nextByte(); // 1\nbyte b7 = in.nextByte(); // 126, this byte value overflowed! No safety check\n                         // gets done for this. It is assumed the user knows\n                         // the range of the values they're reading from the stream.\nbyte b8 = in.nextByte(); // Nothing left in stream so an exception is thrown\n```\n\n#### .nextInt() examples\n``` java\n// Suppose standard input stream contains the following byte values we want to read:\n\"2147483647 -2147483648 34545 -1 -0 0 1 999999999999\"\n//                                          ^ NOTE: This does NOT fit in a signed int!\n\nInputReader in = new InputReader();\nint integer1 = in.nextInt(); // 2147483647\nint integer2 = in.nextInt(); // -2147483648\nint integer3 = in.nextInt(); // 34545\nint integer4 = in.nextInt(); // -1\nint integer5 = in.nextInt(); // 0\nint integer6 = in.nextInt(); // 0\nint integer7 = in.nextInt(); // 1\nint integer8 = in.nextInt(); // -727379969, this int value overflowed! No safety check   \n                             // gets done for this. It is assumed the user knows the \n                             // range of the values they're reading from the stream\nint integer9 = in.nextInt(); // Nothing left in stream so an exception is thrown\n```\n\n#### .nextString() example\n\n``` java\n// Suppose standard input stream contains the following string and we want\n// to read the individual fruits names contained inside this sentence. We\n// Can easily do this by using the .nextString()\n\"Apple banana orange\\n\\n KiWi dragonFRuIt \\n   \\n  WatERmeOn  \\n\\n\\nPEARS\\n\\n   \"\n\nInputReader in = new InputReader();\nString s1 = in.nextString(); // \"Apple\"\nString s2 = in.nextString(); // \"banana\"\nString s3 = in.nextString(); // \"orange\"\nString s4 = in.nextString(); // \"KiWi\"\nString s5 = in.nextString(); // \"dragonFRuIt\"\nString s6 = in.nextString(); // \"WatERmeOn\"\nString s7 = in.nextString(); // \"PEARS\"\nString s8 = in.nextString(); // null - Returns null when no more strings are found in the input stream\n```\n\n#### .nextLine() example\n\n``` java\n// Suppose standard input stream contains the following string and we want\n// to read it line by line. We can do this using the .nextLine() method\n\"Apple banana orange\\n\\n KiWi dragonFRuIt \\n   \\n  WatERmelOn  \\n\\n\\nPEARS\\n\\n   \"\n\nInputReader in = new InputReader();\nString s1  = in.nextLine(); // \"Apple banana orange\"\nString s2  = in.nextLine(); // \"\"\nString s3  = in.nextLine(); // \" KiWi dragonFRuIt \"\nString s4  = in.nextLine(); // \"   \"\nString s5  = in.nextLine(); // \"  WatERmelOn  \"\nString s6  = in.nextLine(); // \"\"\nString s7  = in.nextLine(); // \"\"\nString s8  = in.nextLine(); // \"PEARS\"\nString s9  = in.nextLine(); // \"\"\nString s10 = in.nextLine(); // \"   \"\nString s11 = in.nextLine(); // null - No more lines left so null is returned\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamfiset%2Ffastjavaio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilliamfiset%2Ffastjavaio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamfiset%2Ffastjavaio/lists"}