Code example for ByteArrayInputStream

Methods: available

0
        } 
    } 
     
    private void uploadStringFromClipboard(String s) {
        try { 
            ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes("utf-8"));
            String filename = String.format("Snippet %s.txt", df.format(new Date()));
             
            setImageWorking(); 
            JSONObject drop = client.uploadFile(new CloudAppInputStream(bais, "text/plain", filename, bais.available()));
            String url = getDropUrl(drop);
            System.out.println("Upload complete, URL:\n"+url);
            setClipboard(url);
            icon.displayMessage("Upload finished", String.format("Item: %s", filename), TrayIcon.MessageType.INFO);
        } catch(IOException ex) {
            icon.displayMessage("Upload failed", ex.toString(), TrayIcon.MessageType.ERROR);
        } catch(CloudApiException ex) {
            icon.displayMessage("Upload failed", ex.toString(), TrayIcon.MessageType.ERROR);
        } finally { 
            setImageNormal(); 
        }