lpr-b:sorgenteodp
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| lpr-b:sorgenteodp [26/10/2007 alle 15:38 (18 anni fa)] – creata Marco Danelutto | lpr-b:sorgenteodp [26/10/2007 alle 15:39 (18 anni fa)] (versione attuale) – Marco Danelutto | ||
|---|---|---|---|
| Linea 26: | Linea 26: | ||
| public class ODP { | public class ODP { | ||
| - | private static final int MAX_UDP_PAYLOAD = 65507; | + | private static final int MAX_UDP_PAYLOAD = 65507; |
| - | /** | + | /** |
| - | * variabile utilizzata per memorizzare l' | + | * variabile utilizzata per memorizzare l' |
| - | * (o che e' stato) serializzato mediante il DatagramPacket. | + | * (o che e' stato) serializzato mediante il DatagramPacket. |
| - | */ | + | */ |
| - | private Object o = null; | + | private Object o = null; |
| - | | + | /** |
| - | | + | * costruttore per la creazione di un ODP |
| - | | + | * Questo costruttore si usa per creare un pacchetto da spedire. |
| - | | + | * @param o l' |
| - | | + | */ |
| - | public ODP(Object o) { | + | public ODP(Object o) { |
| - | this.o = o; | + | this.o = o; |
| - | } | + | } |
| - | + | ||
| - | /** | + | |
| - | * creazione di un oggetto ODP a partire da un pacchetto DatagramPacket. Si passa il datagram packet come parametro | + | |
| - | * e da questo si ottiene l' | + | |
| - | * @param dp il DatagramPacket da cui si crea l' | + | |
| - | * @return l' | + | |
| - | */ | + | |
| - | public static ODP getODP(DatagramPacket dp) { | + | |
| - | ODP o = null; | + | |
| - | try { | + | |
| - | ByteArrayInputStream bis = new ByteArrayInputStream(dp.getData()); | + | |
| - | ObjectInputStream ois = new ObjectInputStream(bis); | + | |
| - | o = new ODP(ois.readObject()); | + | |
| - | } catch (IOException e) { | + | |
| - | e.printStackTrace(); | + | |
| - | } catch (ClassNotFoundException e) { | + | |
| - | e.printStackTrace(); | + | |
| - | } | + | |
| - | return o; | + | |
| - | | + | |
| - | | + | /** |
| - | | + | * creazione di un oggetto ODP a partire da un pacchetto DatagramPacket. Si passa il datagram packet come parametro |
| - | | + | * e da questo si ottiene |
| - | | + | * @param |
| - | | + | * @return |
| - | * @throws Exception | + | */ |
| - | | + | public |
| - | public | + | ODP o = null; |
| - | | + | ByteArrayInputStream bis = new ByteArrayInputStream(dp.getData()); |
| - | | + | ObjectInputStream ois = new ObjectInputStream(bis); |
| - | try { | + | o = new ODP(ois.readObject()); |
| - | oos = new ObjectOutputStream(bos); | + | return |
| - | oos.writeObject(o); | + | } |
| - | } catch (IOException e) { | + | |
| - | e.printStackTrace(); | + | |
| - | } | + | |
| - | byte[] buf = bos.toByteArray(); | + | |
| - | if(buf.length > MAX_UDP_PAYLOAD) | + | |
| - | throw | + | |
| - | | + | |
| - | return | + | |
| - | } | + | |
| - | | + | /** |
| - | | + | * metodo per ottenere un DatagramPacket dall' |
| - | | + | * @param addr l' |
| - | | + | * @param port porta destinazione per il pacchetto |
| - | | + | * @return il datagram packet con l' |
| - | public Object getObject() { | + | * @throws Exception |
| - | return o; | + | */ |
| - | } | + | public DatagramPacket getDatagramPacket(InetAddress addr, int port) throws IOException { |
| + | ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
| + | ObjectOutputStream oos; | ||
| + | try { | ||
| + | oos = new ObjectOutputStream(bos); | ||
| + | oos.writeObject(o); | ||
| + | } catch (IOException e) { | ||
| + | e.printStackTrace(); | ||
| + | } | ||
| + | byte[] buf = bos.toByteArray(); | ||
| + | if(buf.length > MAX_UDP_PAYLOAD) | ||
| + | throw new IOException(" | ||
| + | DatagramPacket dp = new DatagramPacket(buf, | ||
| + | return (dp); | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * utilizzata per prelevare l' | ||
| + | * @return l' | ||
| + | * | ||
| + | */ | ||
| + | public Object getObject() { | ||
| + | return o; | ||
| + | } | ||
| } | } | ||
| </ | </ | ||
lpr-b/sorgenteodp.1193413085.txt.gz · Ultima modifica: 26/10/2007 alle 15:38 (18 anni fa) da Marco Danelutto
