X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Futil%2Ffreenet%2Ffcp2%2FMessage.java;fp=src%2Fde%2Ftodesbaum%2Futil%2Ffreenet%2Ffcp2%2FMessage.java;h=a8460f80d1a8699bcec0cbf21b9decad5d56a1d2;hb=6f1a8216cfba28add0ef365b46a08d16d4eb87fe;hp=0000000000000000000000000000000000000000;hpb=10df11c06704254df61e030dc4a772204759560d;p=jSite.git
diff --git a/src/de/todesbaum/util/freenet/fcp2/Message.java b/src/de/todesbaum/util/freenet/fcp2/Message.java
new file mode 100644
index 0000000..a8460f8
--- /dev/null
+++ b/src/de/todesbaum/util/freenet/fcp2/Message.java
@@ -0,0 +1,175 @@
+/*
+ * todesbaum-lib -
+ * Copyright (C) 2006 David Roden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package de.todesbaum.util.freenet.fcp2;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+/**
+ * Contains replies sent by the Freenet node. A message always has a name, and
+ * most of the messages also have an identifier which binds it to a specific
+ * command. Exceptions are among others NodeHello
,
+ * SSKKeypair
, and EndListPersistentRequests
.
+ *
+ * @author David Roden <droden@gmail.com>
+ * @version $Id: Message.java 413 2006-03-29 12:22:31Z bombe $
+ * @see de.todesbaum.util.freenet.fcp2.Client
+ */
+public class Message {
+
+ /** The name of this message. */
+ private final String name;
+
+ /** The identifier of this message. */
+ private String identifier = "";
+
+ /** The parameters of this message. */
+ private Map parameters = new HashMap();
+
+ /** The payload. */
+ private InputStream payloadInputStream;
+
+ /**
+ * Creates a new message with the specified name.
+ *
+ * @param name
+ * The name of this message
+ */
+ public Message(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the identifier of this message.
+ *
+ * @return The identifier
+ */
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /**
+ * Sets the identifier of this message.
+ *
+ * @param identifier
+ * The identifier of this message
+ */
+ public void setIdentifier(String identifier) {
+ this.identifier = identifier;
+ }
+
+ /**
+ * Returns the name of this message.
+ *
+ * @return The name of this message
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Tests whether this message contains the parameter with the specified key.
+ * Key names are compared ignoring case.
+ *
+ * @param key
+ * The name of the parameter
+ * @return true
if this parameter exists in this message,
+ * false
otherwise
+ */
+ public boolean containsKey(String key) {
+ return parameters.containsKey(key.toLowerCase());
+ }
+
+ /**
+ * Returns all parameters of this message. The keys of the entries are all
+ * lower case so if you want to match the parameter names you have to watch
+ * out.
+ *
+ * @return All parameters of this message
+ */
+ public Set> entrySet() {
+ return parameters.entrySet();
+ }
+
+ /**
+ * Returns the value of the parameter with the name specified by
+ * key
.
+ *
+ * @param key
+ * The name of the parameter
+ * @return The value of the parameter
+ */
+ public String get(String key) {
+ return parameters.get(key.toLowerCase());
+ }
+
+ /**
+ * Stores the specified value as parameter with the name specified by
+ * key
.
+ *
+ * @param key
+ * The name of the parameter
+ * @param value
+ * The value of the parameter
+ * @return The previous value, or null
if there was no
+ * previous value
+ */
+ public String put(String key, String value) {
+ return parameters.put(key.toLowerCase(), value);
+ }
+
+ /**
+ * Returns the number of parameters in this message.
+ *
+ * @return The number of parameters
+ */
+ public int size() {
+ return parameters.size();
+ }
+
+ /**
+ * @return Returns the payloadInputStream.
+ */
+ public InputStream getPayloadInputStream() {
+ return payloadInputStream;
+ }
+
+ /**
+ * @param payloadInputStream
+ * The payloadInputStream to set.
+ */
+ public void setPayloadInputStream(InputStream payloadInputStream) {
+ this.payloadInputStream = payloadInputStream;
+ }
+
+ /**
+ * Returns a textual representation of this message, containing its name,
+ * the identifier, and the parameters.
+ *
+ * @return A textual representation of this message
+ */
+ public String toString() {
+ return name + "[identifier=" + identifier + ",parameters=" + parameters.toString() + "]";
+ }
+
+}