MCPcopy Create free account
hub / github.com/antlr/codebuff / readFile

Method readFile

corpus/java/training/guava/io/Files.java:165–176  ·  view source on GitHub ↗

Reads a file of the given expected size from the given input stream, if it will fit into a byte array. This method handles the case where the file size changes between when the size is read and when the contents are read from the stream.

(InputStream in, long expectedSize)

Source from the content-addressed store, hash-verified

163 * and when the contents are read from the stream.
164 */
165 static byte[] readFile(InputStream in, long expectedSize) throws IOException {
166 if (expectedSize > Integer.MAX_VALUE) {
167 throw new OutOfMemoryError(
168 "file is too large to fit in a byte array: " + expectedSize + " bytes");
169 }
170
171 // some special files may return size 0 but have content, so read
172 // the file normally in that case
173 return expectedSize == 0
174 ? ByteStreams.toByteArray(in)
175 : ByteStreams.toByteArray(in, (int) expectedSize);
176 }
177
178 /**
179 * Returns a new {@link ByteSink} for writing bytes to the given file. The given {@code modes}

Callers 1

readMethod · 0.45

Calls 1

toByteArrayMethod · 0.95

Tested by

no test coverage detected