while (--timeout > 0 && !attachment.available()) { Thread.sleep(1000); } if (!attachment.available()) { throw new RuntimeException("Uploading track timeout"); }