private void readFromStorableInput(String filename) { try { URL url = new URL(getCodeBase(), filename); InputStream stream = url.openStream(); StorableInput input = new StorableInput(stream); fDrawing.release(); fDrawing = (Drawing) input.readStorable(); view().setDrawing(fDrawing); } catch (IOException e) { initDrawing(); showStatus("Error:" + e); } }
private void readFromObjectInput(String filename) { try { URL url = new URL(getCodeBase(), filename); InputStream stream = url.openStream(); ObjectInput input = new ObjectInputStream(stream); fDrawing.release(); fDrawing = (Drawing) input.readObject(); view().setDrawing(fDrawing); } catch (IOException e) { initDrawing(); showStatus("Error: " + e); } catch (ClassNotFoundException e) { initDrawing(); showStatus("Class not found: " + e); } }
public void fetchExternalJSLibrary(String targetURLString) { final URL targetURL; String targetFile = ""; String s = null; InputStream is = null; BufferedReader dis = null; try { // ------------------------------------------------------------// // Step 2: Create the URL. // // ------------------------------------------------------------// // Note: Put your real URL here, or better yet, read it as a // // command-line arg, or read it from a file. // // ------------------------------------------------------------// targetURL = new URL(targetURLString); // ----------------------------------------------// // Step 3: Open an input stream from the url. // // ----------------------------------------------// is = targetURL.openStream(); // -------------------------------------------------------------// // Step 4: // // -------------------------------------------------------------// // Convert the InputStream to BufferedReader // // -------------------------------------------------------------// dis = new BufferedReader(new InputStreamReader(is)); // ------------------------------------------------------------// // Step 5: // // ------------------------------------------------------------// // Now just read each record of the input stream, and print // // it out. Note that it's assumed that this problem is run // // from a command-line, not from an application or applet. // // ------------------------------------------------------------// while ((s = dis.readLine()) != null) { targetFile = targetFile + "\n" + s; } alert(targetFile); System.out.println(targetFile); } catch (MalformedURLException mue) { alert("Ouch - a MalformedURLException happened."); System.out.println("Ouch - a MalformedURLException happened."); mue.printStackTrace(); System.exit(1); } catch (IOException ioe) { alert("Ouch - an IOException happened."); System.out.println("Ouch - an IOException happened."); ioe.printStackTrace(); System.exit(1); } catch (Exception e) { alert("Ouch - Something wrong happened."); alert(e.toString()); alert(e.getMessage()); } finally { // ---------------------------------// // Step 6: Close the InputStream // // ---------------------------------// try { is.close(); dis.close(); } catch (IOException ioe) { // just going to ignore this one } } // end of 'finally' clause }
private void buttonOKActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_buttonOKActionPerformed // verification si les champs sont vides if (textIndDestinataire.getText().equals("") || textIndObjet.getText().equals("") || textMessage.getText().equals("")) { JOptionPane.showMessageDialog( this, Bundle.getText("JDialogAlerteChampsVides"), Bundle.getText("JDialogAlerteAttentionMessage"), JOptionPane.WARNING_MESSAGE); return; } try { // Envoie du login et du password a la servlet "CreerSuperviseurServlet" pour l'ajouter a la // BD URL url = new URL( "http://" + P2S.P2S.Preferences.getProperty("host") + ":" + P2S.P2S.Preferences.getProperty("port") + "/p2sserver/CreerUnMessageServlet?login="******"&sujet=" + this.textIndObjet.getText() + "&message=" + this.textMessage.getText()); // Buffer qui va recuperer la reponse de la servlet BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); // On recupere la reponse String inputLine = in.readLine(); if (inputLine.equalsIgnoreCase("ok")) { // on a enregistré dans la bd this.dispose(); in.close(); return; } else if (inputLine.equalsIgnoreCase("nok")) { JOptionPane.showMessageDialog( this, Bundle.getText("JDialogAlerteNoSup"), Bundle.getText("JDialogAlerteAttentionMessage"), JOptionPane.WARNING_MESSAGE); } in.close(); } catch (MalformedURLException e1) { javax.swing.JOptionPane.showMessageDialog( null, Bundle.getText("ExceptionErrorURL"), Bundle.getText("ExceptionErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE); } catch (IOException e2) { javax.swing.JOptionPane.showMessageDialog( null, Bundle.getText("ExceptionErrorIO"), Bundle.getText("ExceptionErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE); } catch (IllegalArgumentException e3) { javax.swing.JOptionPane.showMessageDialog( null, Bundle.getText("ExceptionErrorARGS"), Bundle.getText("ExceptionErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE); } } // GEN-LAST:event_buttonOKActionPerformed