defensive-coding-guide/pot/Java/snippets/Language-ReadArray.pot

53 lines
1.4 KiB
Text

#
# AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: 0\n"
"POT-Creation-Date: 2013-08-13T01:54:52\n"
"PO-Revision-Date: 2013-08-13T01:54:52\n"
"Last-Translator: Automatically generated\n"
"Language-Team: None\n"
"MIME-Version: 1.0\n"
"Content-Type: application/x-publican; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. Tag: programlisting
#, no-c-format
msgid "\n"
"static byte[] readBytes(InputStream in, int length) throws IOException {\n"
" final int startSize = 65536;\n"
" byte[] b = new byte[Math.min(length, startSize)];\n"
" int filled = 0;\n"
" while (true) {\n"
" int remaining = b.length - filled;\n"
" readFully(in, b, filled, remaining);\n"
" if (b.length == length) {\n"
" break;\n"
" }\n"
" filled = b.length;\n"
" if (length - b.length &lt;= b.length) {\n"
" // Allocate final length. Condition avoids overflow.\n"
" b = Arrays.copyOf(b, length);\n"
" } else {\n"
" b = Arrays.copyOf(b, b.length * 2);\n"
" }\n"
" }\n"
" return b;\n"
"}\n"
"\n"
"static void readFully(InputStream in,byte[] b, int off, int len)\n"
" throws IOException {\n"
" int startlen = len;\n"
" while (len &gt; 0) {\n"
" int count = in.read(b, off, len);\n"
" if (count &lt; 0) {\n"
" throw new EOFException();\n"
" }\n"
" off += count;\n"
" len -= count;\n"
" }\n"
"}\n"
""
msgstr ""