177 int commandSize = -1;
178 final StringBuilder storage =
new StringBuilder(p_leftString != null ? p_leftString :
"");
180 LOG.trace(
"commandSize: {}, stringStorage: {}", commandSize, storage.toString());
183 final int readCount = p_reader.read(buffer, 0,
BUFFER_SIZE);
184 if (readCount == -1) {
185 LOG.trace(
"End of stream. Quit.");
189 storage.append(buffer, 0, readCount);
191 final int storageLength = storage.length();
192 if (commandSize == -1 && storageLength >=
CoreUtils.COMMAND_STR_LENGTH_SIZE) {
193 final String sizeString = storage.substring(0,
CoreUtils.COMMAND_STR_LENGTH_SIZE);
194 commandSize = (int)
CoreUtils.parseSilently(sizeString);
195 LOG.trace(
"Parsed sizeString: {}, commandSize: {}", sizeString, commandSize);
197 if (commandSize == -1) {
198 LOG.trace(
"Unable to identify command size. Quit.");
203 final int totalSize = commandSize +
CoreUtils.COMMAND_STR_LENGTH_SIZE;
204 if (commandSize != -1 && storageLength >= totalSize) {
205 final String commandAsString = storage.substring(
206 CoreUtils.COMMAND_STR_LENGTH_SIZE, totalSize);
208 String leftString =
"";
209 if (storageLength > (totalSize + 1)) {
210 storage.substring(totalSize + 1);
212 final ReadResult result =
new ReadResult(commandAsString, leftString);
213 LOG.trace(
"Read result: {}", result);
static final Logger LOG
Definition: CoreUtils.java:81
CoreUtils()
Definition: CoreUtils.java:89
static final int BUFFER_SIZE
Definition: CoreUtils.java:84