Thread: [Beepcore-java-commits] CVS: beepcore-java/src/org/beepcore/beep/core ByteOutputDataStream.java,NONE
Status: Beta
Brought to you by:
huston
From: Huston F. <hu...@us...> - 2001-11-10 21:33:31
|
Update of /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/core In directory usw-pr-cvs1:/tmp/cvs-serv17519/src/org/beepcore/beep/core Modified Files: MessageMSG.java Session.java Added Files: ByteOutputDataStream.java StringOutputDataStream.java Removed Files: ByteDataStream.java StringDataStream.java Log Message: Rename Byte/StringDataStream to Byte/StringOutputDataStream --- NEW FILE: ByteOutputDataStream.java --- /* * ByteOutputDataStream.java $Revision: 1.1 $ $Date: 2001/11/10 21:33:29 $ * * Copyright (c) 2001 Huston Franklin. All rights reserved. * * The contents of this file are subject to the Blocks Public License (the * "License"); You may not use this file except in compliance with the License. * * You may obtain a copy of the License at http://www.beepcore.org/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * */ package org.beepcore.beep.core; import java.util.Enumeration; import org.beepcore.beep.util.BufferSegment; /** * <code>ByteOutputDataStream</code> represents a BEEP message's * payload. Allows the implementor to treat a <code>byte[]</code> as * a <code>DataStream</code>. <p> <b>Note that this implementation is * not synchronized.</b> If multiple threads access a * <code>ByteOutputDataStream</code> concurrently, data may be * inconsistent or lost. * * @see org.beepcore.beep.core.DataStream * * @author Huston Franklin * @version $Revision: 1.1 $, $Date: 2001/11/10 21:33:29 $ */ public class ByteOutputDataStream extends OutputDataStream { /** * Creates a <code>ByteOutputDataStream</code> from a * <code>byte[]</code> with a content type of * <code>DEFAULT_CONTENT_TYPE</code> and a transfer encoding of * <code>DEFAULT_CONTENT_TRANSFER_ENCODING</code>. * * @param data A <code>byte[]</code> representing a message's payload. */ public ByteOutputDataStream(byte[] data) { this(data, 0, data.length); } /** * Creates a <code>ByteOutputDataStream</code> from a <code>byte[]</code> * with a specified content type and a transfer encoding * of <code>DEFAULT_CONTENT_TRANSFER_ENCODING</code>. * * @param contentType Content type of <code>data</code>. * @param data A <code>byte[]</code> representing a message's payload. */ public ByteOutputDataStream(String contentType, byte[] data) { this(contentType, data, 0, data.length); } /** * Creates a <code>ByteOutputDataStream</code> from a <code>byte[]</code> * with a specified content type and a specified transfer encoding. * * @param contentType Content type of <code>data</code>. * @param transferEncoding Encoding Transfer encoding type of * <code>data</code>. * @param data A <code>byte[]</code> representing a message's payload. */ public ByteOutputDataStream(String contentType, String transferEncoding, byte[] data) { this(contentType, transferEncoding, data, 0, data.length); } /** * Creates a <code>ByteOutputDataStream</code> from a * <code>byte[]</code> using the specified length and offset with * a content type of <code>DEFAULT_CONTENT_TYPE</code> and a * transfer encoding of * <code>DEFAULT_CONTENT_TRANSFER_ENCODING</code>. * * @param data A <code>byte[]</code> representing a message's payload. * @param offset The start offset in array <code>data</code> at which the * data is written. * @param length The maximum number of bytes to read. */ public ByteOutputDataStream(byte[] data, int offset, int length) { super(new MimeHeaders(), new BufferSegment(data, offset, length)); } /** * Creates a <code>ByteOutputDataStream</code> from a * <code>byte[]</code> using the specified length and offset and * with a specified content type and a transfer encoding of * <code>DEFAULT_CONTENT_TRANSFER_ENCODING</code>. * * @param contentType Content type of <code>byte[]</code>. * @param data A <code>byte[]</code> representing a message's payload. * @param offset The start offset in array <code>data</code> at which the * data is written. * @param length The maximum number of bytes to read. */ public ByteOutputDataStream(String contentType, byte[] data, int offset, int length) { super(new MimeHeaders(contentType), new BufferSegment(data, offset, length)); } /** * Creates a <code>ByteOutputDataStream</code> from a * <code>byte[]</code> using the specified length and offset and * with a specified content type and a specified transfer * encoding. * * @param contentType Content type of <code>byte[]</code>. * @param transferEncoding Encoding Transfer encoding type of * <code>data</code>. * @param data A <code>byte[]</code> representing a message's payload. * @param offset The start offset in array <code>data</code> at which the * data is written. * @param length The maximum number of bytes to read. */ public ByteOutputDataStream(String contentType, String transferEncoding, byte[] data, int offset, int length) { super(new MimeHeaders(contentType, transferEncoding), new BufferSegment(data, offset, length)); } /** * Returns <code>true</code> if no more bytes will be added to those * currently available, if any, on this stream. Returns * <code>false</code> if more bytes are expected. */ public boolean isComplete() { return true; } /** * Returns the value of the MIME entity header <code>Content-Type</code>. */ public String getContentType() throws BEEPException { return this.mimeHeaders.getContentType(); } /** * Sets the content type of a <code>DataStream</code>. * * @param contentType */ public void setContentType(String contentType) { this.mimeHeaders.setContentType(contentType); } /** * Returns the value of the MIME entity header * <code>Content-Transfer-Encoding</code>. */ public String getTransferEncoding() throws BEEPException { return this.mimeHeaders.getTransferEncoding(); } /** * Sets the content transfer encoding of a <code>DataStream</code> * * @param transferEncoding */ public void setTransferEncoding(String transferEncoding) { this.mimeHeaders.setTransferEncoding(transferEncoding); } /** * Returns an <code>Enumeration</code> of all the names of the MIME entity * headers in this data stream. * Use this call in conjunction with <code>getHeaderValue</code> to iterate * through all the corresponding MIME entity header <code>value</code>(s) * in this data stream. * * @return An <code>Enumeration</code> of all the MIME entity header * names. * * @throws BEEPException */ public Enumeration getHeaderNames() throws BEEPException { return this.mimeHeaders.getHeaderNames(); } /** * Retrieves the correspoding <code>value</code> to a given a MIME entity * header <code>name</code>. * * @param name Name of the MIME entity header. * @return The <code>value</code> of the MIME entity header. * * @throws BEEPException */ public String getHeaderValue(String name) throws BEEPException { return this.mimeHeaders.getHeaderValue(name); } /** * Adds a MIME entity header to this data stream. * * @param name Name of the MIME enitity header. * @param value Value of the MIME entity header. */ public void setHeaderValue(String name, String value) { this.mimeHeaders.setHeader(name, value); } /** * Removes the <code>name</code> and <code>value</code> of a MIME entity * header from the data stream. Returns <code>true</code> if the * <code>name</code> was successfully removed. * * @param name Name of the header to be removed from the data stream. * * @return Returns </code>true<code> if header was removed. Otherwise, * returns <code>false</code>. */ public boolean removeHeader(String name) { return this.mimeHeaders.removeHeader(name); } } --- NEW FILE: StringOutputDataStream.java --- /* * StringOutputDataStream.java $Revision: 1.1 $ $Date: 2001/11/10 21:33:29 $ * * Copyright (c) 2001 Invisible Worlds, Inc. All rights reserved. * Copyright (c) 2001 Huston Franklin. All rights reserved. * * The contents of this file are subject to the Blocks Public License (the * "License"); You may not use this file except in compliance with the License. * * You may obtain a copy of the License at http://www.beepcore.org/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * */ package org.beepcore.beep.core; import java.util.Enumeration; import java.util.MissingResourceException; import java.io.UnsupportedEncodingException; import java.io.IOException; import org.beepcore.beep.util.BufferSegment; /** * <code>StringOutputDataStream</code> represents a BEEP message's * payload. Allows implementors to treat a <code>String</code> as a * <code>DataSream</code>. The <code>String</code> is stored as a * <code>byte[]</code> using UTF-8 encoding. <p> <b>Note that this * implementation is not synchronized.</b> If multiple threads access * a <code>StringOutputDataStream</code> concurrently, data may be * inconsistent or lost. * * @see org.beepcore.beep.core.DataStream * * @author Eric Dixon * @author Huston Franklin * @author Jay Kint * @author Scott Pead * @version $Revision: 1.1 $, $Date: 2001/11/10 21:33:29 $ */ public class StringOutputDataStream extends OutputDataStream { /** * The default <code>StringOutputDataStream</code> String encoding * ("UTF-8"). */ private static final String DEFAULT_STRING_ENCODING = "UTF-8"; private String enc; /** * Creates a <code>StringOutputDataStream</code> with a * <code>String</code> and a <code>BEEP_XML_CONTENT_TYPE</code> * content type and a transfer encoding of * <code>DEFAULT_CONTENT_TRANSFER_ENCODING</code>. * * @param data A <code>String</code> representing a message's payload. */ public StringOutputDataStream(String data) { super(new MimeHeaders()); try { add(new BufferSegment(data.getBytes(DEFAULT_STRING_ENCODING))); this.enc = DEFAULT_STRING_ENCODING; } catch (UnsupportedEncodingException e) { throw new MissingResourceException("Encoding " + DEFAULT_STRING_ENCODING + " not supported", "StringOutputDataStream", DEFAULT_STRING_ENCODING); } } /** * Creates a <code>StringOutputDataStream</code> with a * <code>String</code> and a specified content type and a transfer * encoding of <code>DEFAULT_CONTENT_TRANSFER_ENCODING</code>. * * @param contentType Content type of <code>data</code> * @param data A <code>String</code> representing a message's payload. */ public StringOutputDataStream(String contentType, String data) { super(new MimeHeaders(contentType)); try { add(new BufferSegment(data.getBytes(DEFAULT_STRING_ENCODING))); this.enc = DEFAULT_STRING_ENCODING; } catch (UnsupportedEncodingException e) { throw new MissingResourceException("Encoding " + DEFAULT_STRING_ENCODING + " not supported", "StringOutputDataStream", DEFAULT_STRING_ENCODING); } } /** * Creates a <code>StringOutputDataStream</code> with a * <code>String</code> and a specified content type and a transfer * encoding of <code>DEFAULT_CONTENT_TRANSFER_ENCODING</code>. * * @param contentType Content type of <code>data</code> * @param transferEncoding Encoding Transfer encoding type of * <code>data</code>. * @param data A <code>String</code> representing a message's payload. */ public StringOutputDataStream(String contentType, String transferEncoding, String data) { super(new MimeHeaders(contentType, transferEncoding)); try { add(new BufferSegment(data.getBytes(DEFAULT_STRING_ENCODING))); this.enc = DEFAULT_STRING_ENCODING; } catch (UnsupportedEncodingException e) { throw new MissingResourceException("Encoding " + DEFAULT_STRING_ENCODING + " not supported", "StringOutputDataStream", DEFAULT_STRING_ENCODING); } } /** * Creates a <code>StringOutputDataStream</code> with a * <code>String</code> and a specified content type and encoding. * * @param contentType Content type of <code>data</code> * @param transferEncoding Encoding Transfer encoding type of * <code>data</code>. * @param data A <code>String</code> representing a message's payload. * @param enc The encoding used when converting <code>data</code> to a * <code>bytes[]</code>. */ public StringOutputDataStream(String contentType, String transferEncoding, String data, String enc) throws UnsupportedEncodingException { super(new MimeHeaders(contentType, transferEncoding)); add(new BufferSegment(data.getBytes(DEFAULT_STRING_ENCODING))); this.enc = DEFAULT_STRING_ENCODING; } /** * Returns the encoding used to convert the <code>String</code> to a * <code>bytes[]</code>. */ public String getEncoding() { return this.enc; } /** * Returns <code>true</code> if no more bytes will be added to those * currently available, if any, on this stream. Returns * <code>false</code> if more bytes are expected. */ public boolean isComplete() { return true; } /** * Returns the value of the MIME entity header <code>Content-Type</code>. */ public String getContentType() throws BEEPException { return this.mimeHeaders.getContentType(); } /** * Sets the content type of a <code>DataStream</code>. * * @param contentType */ public void setContentType(String contentType) { this.mimeHeaders.setContentType(contentType); } /** * Returns an <code>Enumeration</code> of all the names of the MIME entity * headers in this data stream. * Use this call in conjunction with <code>getHeaderValue</code> to iterate * through all the corresponding MIME entity header <code>value</code>(s) * in this data stream. * * @return An <code>Enumeration</code> of all the MIME entity header * names. * * @throws BEEPException */ public Enumeration getHeaderNames() throws BEEPException { return this.mimeHeaders.getHeaderNames(); } /** * Retrieves the correspoding <code>value</code> to a given a MIME entity * header <code>name</code>. * * @param name Name of the MIME entity header. * @return The <code>value</code> of the MIME entity header. * * @throws BEEPException */ public String getHeaderValue(String name) throws BEEPException { return this.mimeHeaders.getHeaderValue(name); } /** * Adds a MIME entity header to this data stream. * * @param name Name of the MIME enitity header. * @param value Value of the MIME entity header. */ public void setHeaderValue(String name, String value) { this.mimeHeaders.setHeader(name, value); } /** * Returns the value of the MIME entity header * <code>Content-Transfer-Encoding</code>. */ public String getTransferEncoding() throws BEEPException { return this.mimeHeaders.getTransferEncoding(); } /** * Sets the content transfer encoding of a <code>DataStream</code> * * @param transferEncoding */ public void setTransferEncoding(String transferEncoding) { this.mimeHeaders.setTransferEncoding(transferEncoding); } /** * Removes the <code>name</code> and <code>value</code> of a MIME entity * header from the data stream. Returns <code>true</code> if the * <code>name</code> was successfully removed. * * @param name Name of the header to be removed from the data stream. * * @return Returns </code>true<code> if header was removed. Otherwise, * returns <code>false</code>. */ public boolean removeHeader(String name) { return this.mimeHeaders.removeHeader(name); } } Index: MessageMSG.java =================================================================== RCS file: /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/core/MessageMSG.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** MessageMSG.java 2001/11/08 05:51:34 1.5 --- MessageMSG.java 2001/11/10 21:33:29 1.6 *************** *** 79,83 **** { OutputDataStream stream = ! new StringDataStream(error.createErrorMessage()); MessageStatus m = new MessageStatus(this.channel, MESSAGE_TYPE_ERR, this.msgno, stream); --- 79,83 ---- { OutputDataStream stream = ! new StringOutputDataStream(error.createErrorMessage()); MessageStatus m = new MessageStatus(this.channel, MESSAGE_TYPE_ERR, this.msgno, stream); *************** *** 104,108 **** MessageStatus m = new MessageStatus(this.channel, MESSAGE_TYPE_ERR, this.msgno, ! new StringDataStream(error)); this.channel.sendMessage(m); return m; --- 104,108 ---- MessageStatus m = new MessageStatus(this.channel, MESSAGE_TYPE_ERR, this.msgno, ! new StringOutputDataStream(error)); this.channel.sendMessage(m); return m; *************** *** 129,133 **** MessageStatus m = new MessageStatus(this.channel, MESSAGE_TYPE_ERR, this.msgno, ! new StringDataStream(error)); this.channel.sendMessage(m); return m; --- 129,133 ---- MessageStatus m = new MessageStatus(this.channel, MESSAGE_TYPE_ERR, this.msgno, ! new StringOutputDataStream(error)); this.channel.sendMessage(m); return m; Index: Session.java =================================================================== RCS file: /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/core/Session.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -r1.18 -r1.19 *** Session.java 2001/11/10 03:58:45 1.18 --- Session.java 2001/11/10 21:33:29 1.19 *************** *** 564,569 **** // Make a message OutputDataStream ds = ! new StringDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, ! startBuffer.toString()); // Tell Channel Zero to start us up --- 564,569 ---- // Make a message OutputDataStream ds = ! new StringOutputDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, ! startBuffer.toString()); // Tell Channel Zero to start us up *************** *** 985,990 **** synchronized (reply) { OutputDataStream ds = ! new StringDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, ! closeBuffer.toString()); this.zero.sendMSG(ds, --- 985,990 ---- synchronized (reply) { OutputDataStream ds = ! new StringOutputDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, ! closeBuffer.toString()); this.zero.sendMSG(ds, *************** *** 1045,1051 **** } ! StringDataStream sds = ! new StringDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, ! sb.toString()); // Store the Channel --- 1045,1051 ---- } ! StringOutputDataStream sds = ! new StringOutputDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, ! sb.toString()); // Store the Channel *************** *** 1099,1105 **** // Send an ok ! StringDataStream sds = ! new StringDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, ! FRAGMENT_OK); try { --- 1099,1105 ---- // Send an ok ! StringOutputDataStream sds = ! new StringOutputDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, ! FRAGMENT_OK); try { *************** *** 1177,1183 **** } ! StringDataStream sds = ! new StringDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, ! FRAGMENT_OK); try { --- 1177,1183 ---- } ! StringOutputDataStream sds = ! new StringOutputDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, ! FRAGMENT_OK); try { *************** *** 1350,1355 **** // get the greeting from the session byte[] greeting = Session.this.getProfileRegistry().getGreeting(this); ! ByteDataStream f = ! new ByteDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, greeting); Message m = new MessageMSG(this.zero, 0, null); --- 1350,1356 ---- // get the greeting from the session byte[] greeting = Session.this.getProfileRegistry().getGreeting(this); ! ByteOutputDataStream f = ! new ByteOutputDataStream(MimeHeaders.BEEP_XML_CONTENT_TYPE, ! greeting); Message m = new MessageMSG(this.zero, 0, null); --- ByteDataStream.java DELETED --- --- StringDataStream.java DELETED --- |