public void nextFrame() throws IOException { if (!client.writeBusy()) { int nextPos = buffer.position(); nextPos = Math.min(nextPos + frameSize, fileSize); buffer.limit(nextPos); client.write(buffer, false); if (nextPos >= fileSize) { this.close(); } } }