@Override
	public List<Framedata> translateFrame(ByteBuffer buffer, int available) {
		List<Framedata> frames = new LinkedList<Framedata>();
		int offset = 0;
		Framedata cur;

		if (incompleteframe != null) {
			while (true) {
				try {
					int available_next_byte_count = available;// The number of
																// bytes
																// received
					int expected_next_byte_count = incompleteframe.remaining();// The
																				// number
																				// of
																				// bytes
																				// to
																				// complete
																				// the
																				// incomplete
																				// frame

					if (expected_next_byte_count > available_next_byte_count) {
						// did not receive enough bytes to complete the frame
						incompleteframe.put(buffer.array(), 0,
								available_next_byte_count);
						// assert( buffer.limit() == available_next_byte_count +
						// buffer.position() );
						// buffer.position( available );
						return frames;
					}

					incompleteframe.put(buffer.array(), 0,
							expected_next_byte_count);
					// buffer.position( buffer.position() +
					// expected_next_byte_count );

					cur = translateSingleFrame(incompleteframe, 0,
							incompleteframe.limit());
					frames.add(cur);
					offset = expected_next_byte_count;
					incompleteframe = null;
					break; // go on with the normal frame receival
				} catch (IncompleteException e) {
					// extending as much as suggested
					ByteBuffer extendedframe = ByteBuffer.allocate(e
							.getPreferedSize());
					assert (extendedframe.limit() > incompleteframe.limit());
					extendedframe.put(incompleteframe.array());
					incompleteframe = extendedframe;
				}
			}
		}

		while (offset < available) {// Read as much as possible full frames
			try {
				cur = translateSingleFrame(buffer, offset, available);
				// System.out.println ( "index "+offset+":" + cur );
				offset = buffer.position();
				frames.add(cur);
			} catch (IncompleteException e) {
				// remember the incomplete data
				int pref = e.getPreferedSize();
				incompleteframe = ByteBuffer.allocate(pref);
				incompleteframe.put(buffer.array(), offset, available - offset);
				break;
			}
		}
		return frames;
	}