@Test public void testReader() throws GuacamoleException { final String test = "1.a,2.bc,3.def,10.helloworld;4.test,5.test2;0.;3.foo;"; GuacamoleReader reader = new ReaderGuacamoleReader(new StringReader(test)); GuacamoleInstruction instruction; instruction = reader.readInstruction(); assertNotNull(instruction); assertEquals(3, instruction.getArgs().size()); assertEquals("a", instruction.getOpcode()); assertEquals("bc", instruction.getArgs().get(0)); assertEquals("def", instruction.getArgs().get(1)); assertEquals("helloworld", instruction.getArgs().get(2)); instruction = reader.readInstruction(); assertNotNull(instruction); assertEquals(1, instruction.getArgs().size()); assertEquals("test", instruction.getOpcode()); assertEquals("test2", instruction.getArgs().get(0)); instruction = reader.readInstruction(); assertNotNull(instruction); assertEquals(0, instruction.getArgs().size()); assertEquals("", instruction.getOpcode()); instruction = reader.readInstruction(); assertNotNull(instruction); assertEquals(0, instruction.getArgs().size()); assertEquals("foo", instruction.getOpcode()); instruction = reader.readInstruction(); assertNull(instruction); }
@Override public GuacamoleInstruction readInstruction() throws GuacamoleException { char[] instructionBuffer = read(); if (instructionBuffer == null) return null; int elementStart = 0; Deque<String> elements = new LinkedList<String>(); while (elementStart < instructionBuffer.length) { int lengthEnd = -1; for (int i=elementStart; i<instructionBuffer.length; i++) { if (instructionBuffer[i] == '.') { lengthEnd = i; break; } } if (lengthEnd == -1) throw new GuacamoleServerException("Read returned incomplete instruction."); int length = Integer.parseInt(new String( instructionBuffer, elementStart, lengthEnd - elementStart )); elementStart = lengthEnd + 1; String element = new String( instructionBuffer, elementStart, length ); elements.addLast(element); elementStart += length; char terminator = instructionBuffer[elementStart]; elementStart++; if (terminator == ';') break; } String opcode = elements.removeFirst(); GuacamoleInstruction instruction = new GuacamoleInstruction( opcode, elements.toArray(new String[elements.size()]) ); return instruction; }
ReaderGuacamoleReader implements GuacamoleReader { @Override public GuacamoleInstruction readInstruction() throws GuacamoleException { char[] instructionBuffer = read(); if (instructionBuffer == null) return null; int elementStart = 0; Deque<String> elements = new LinkedList<String>(); while (elementStart < instructionBuffer.length) { int lengthEnd = -1; for (int i=elementStart; i<instructionBuffer.length; i++) { if (instructionBuffer[i] == '.') { lengthEnd = i; break; } } if (lengthEnd == -1) throw new GuacamoleServerException("Read returned incomplete instruction."); int length = Integer.parseInt(new String( instructionBuffer, elementStart, lengthEnd - elementStart )); elementStart = lengthEnd + 1; String element = new String( instructionBuffer, elementStart, length ); elements.addLast(element); elementStart += length; char terminator = instructionBuffer[elementStart]; elementStart++; if (terminator == ';') break; } String opcode = elements.removeFirst(); GuacamoleInstruction instruction = new GuacamoleInstruction( opcode, elements.toArray(new String[elements.size()]) ); return instruction; } }
ReaderGuacamoleReader implements GuacamoleReader { @Override public GuacamoleInstruction readInstruction() throws GuacamoleException { char[] instructionBuffer = read(); if (instructionBuffer == null) return null; int elementStart = 0; Deque<String> elements = new LinkedList<String>(); while (elementStart < instructionBuffer.length) { int lengthEnd = -1; for (int i=elementStart; i<instructionBuffer.length; i++) { if (instructionBuffer[i] == '.') { lengthEnd = i; break; } } if (lengthEnd == -1) throw new GuacamoleServerException("Read returned incomplete instruction."); int length = Integer.parseInt(new String( instructionBuffer, elementStart, lengthEnd - elementStart )); elementStart = lengthEnd + 1; String element = new String( instructionBuffer, elementStart, length ); elements.addLast(element); elementStart += length; char terminator = instructionBuffer[elementStart]; elementStart++; if (terminator == ';') break; } String opcode = elements.removeFirst(); GuacamoleInstruction instruction = new GuacamoleInstruction( opcode, elements.toArray(new String[elements.size()]) ); return instruction; } ReaderGuacamoleReader(Reader input); }
ReaderGuacamoleReader implements GuacamoleReader { @Override public GuacamoleInstruction readInstruction() throws GuacamoleException { char[] instructionBuffer = read(); if (instructionBuffer == null) return null; int elementStart = 0; Deque<String> elements = new LinkedList<String>(); while (elementStart < instructionBuffer.length) { int lengthEnd = -1; for (int i=elementStart; i<instructionBuffer.length; i++) { if (instructionBuffer[i] == '.') { lengthEnd = i; break; } } if (lengthEnd == -1) throw new GuacamoleServerException("Read returned incomplete instruction."); int length = Integer.parseInt(new String( instructionBuffer, elementStart, lengthEnd - elementStart )); elementStart = lengthEnd + 1; String element = new String( instructionBuffer, elementStart, length ); elements.addLast(element); elementStart += length; char terminator = instructionBuffer[elementStart]; elementStart++; if (terminator == ';') break; } String opcode = elements.removeFirst(); GuacamoleInstruction instruction = new GuacamoleInstruction( opcode, elements.toArray(new String[elements.size()]) ); return instruction; } ReaderGuacamoleReader(Reader input); @Override boolean available(); @Override char[] read(); @Override GuacamoleInstruction readInstruction(); }
ReaderGuacamoleReader implements GuacamoleReader { @Override public GuacamoleInstruction readInstruction() throws GuacamoleException { char[] instructionBuffer = read(); if (instructionBuffer == null) return null; int elementStart = 0; Deque<String> elements = new LinkedList<String>(); while (elementStart < instructionBuffer.length) { int lengthEnd = -1; for (int i=elementStart; i<instructionBuffer.length; i++) { if (instructionBuffer[i] == '.') { lengthEnd = i; break; } } if (lengthEnd == -1) throw new GuacamoleServerException("Read returned incomplete instruction."); int length = Integer.parseInt(new String( instructionBuffer, elementStart, lengthEnd - elementStart )); elementStart = lengthEnd + 1; String element = new String( instructionBuffer, elementStart, length ); elements.addLast(element); elementStart += length; char terminator = instructionBuffer[elementStart]; elementStart++; if (terminator == ';') break; } String opcode = elements.removeFirst(); GuacamoleInstruction instruction = new GuacamoleInstruction( opcode, elements.toArray(new String[elements.size()]) ); return instruction; } ReaderGuacamoleReader(Reader input); @Override boolean available(); @Override char[] read(); @Override GuacamoleInstruction readInstruction();  }