Update of /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging
In directory sc8-pr-cvs1:/tmp/cvs-serv15054/src/hk/hku/cecid/phoenix/message/packaging
Modified Files:
AttachmentDataSource.java EbxmlMessage.java MessageHeader.java
MessageOrder.java PartialInputStream.java
Log Message:
Add two constructor on EbxmlMessage which can load
the message from file and InputStream. The logic is re-use the one
from MessageServer.
The logic on MessageServer is changed to allow support on DataSource
as input to load the message.
Change AttachmentDataSource to support DataSource as input.
Change class to reduce warning on making JavaDoc
Reduce the import * and unused import for some of the classes.
format some of the codes.
Index: AttachmentDataSource.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging/AttachmentDataSource.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** AttachmentDataSource.java 13 Jun 2003 06:52:37 -0000 1.9
--- AttachmentDataSource.java 9 Dec 2003 08:59:10 -0000 1.10
***************
*** 107,110 ****
--- 107,112 ----
private long length;
+
+ private DataSource dataSource;
/**
***************
*** 363,373 ****
final InputStream is = new PartialInputStream(fis, offset, length);
loadData(is);
this.contentType = contentType;
this.encoding = encoding;
}
else {
this.contentType = contentType;
this.encoding = encoding;
- this.name = fileName;
this.data = null;
this.offset = offset;
--- 365,393 ----
final InputStream is = new PartialInputStream(fis, offset, length);
loadData(is);
+ }
+ else {
+ this.name = fileName;
+ this.data = null;
+ this.offset = offset;
+ this.length = length;
+ }
+ this.contentType = contentType;
+ this.encoding = encoding;
+ }
+
+ public AttachmentDataSource(DataSource dataSource, long offset, long length,
+ String contentType, String encoding, boolean loadToMem)
+ throws IOException {
+ if (loadToMem) {
+ InputStream fis = dataSource.getInputStream();
+ final InputStream is = new PartialInputStream(fis, offset, length);
+ loadData(is);
this.contentType = contentType;
this.encoding = encoding;
}
else {
+ this.dataSource = dataSource;
this.contentType = contentType;
this.encoding = encoding;
this.data = null;
this.offset = offset;
***************
*** 377,387 ****
private void loadData(InputStream is) throws IOException {
! final byte[] buffer = new byte[4096];
! final ByteArrayOutputStream out = new ByteArrayOutputStream();
! for (int c=is.read(buffer) ; c!=-1 ; c=is.read(buffer))
! out.write(buffer, 0, c);
! this.data = out.toByteArray();
! this.offset = 0;
! this.length = data.length;
}
--- 397,416 ----
private void loadData(InputStream is) throws IOException {
! try {
! final byte[] buffer = new byte[4096];
! final ByteArrayOutputStream out = new ByteArrayOutputStream();
! for (int c=is.read(buffer) ; c!=-1 ; c=is.read(buffer))
! out.write(buffer, 0, c);
! this.data = out.toByteArray();
! this.offset = 0;
! this.length = data.length;
! out.close();
! } catch (IOException e) {
! throw e;
! } finally {
! if (is != null) {
! is.close();
! }
! }
}
***************
*** 409,419 ****
}
else {
! final File file = new File(name);
! if (file.length() < (offset + length)) {
! throw new IOException("Premature end-of-file: file name=" +
! name + " | file length=" + file.length() + " | offset=" +
! offset + " | length to be read=" + length);
}
- final FileInputStream fis = new FileInputStream(name);
is = new PartialInputStream(fis, offset, length);
}
--- 438,453 ----
}
else {
! InputStream fis = null;
! if (dataSource != null) {
! fis = dataSource.getInputStream();
! } else {
! final File file = new File(name);
! if (file.length() < (offset + length)) {
! throw new IOException("Premature end-of-file: file name=" +
! name + " | file length=" + file.length() + " | offset=" +
! offset + " | length to be read=" + length);
! }
! fis = new FileInputStream(name);
}
is = new PartialInputStream(fis, offset, length);
}
***************
*** 476,486 ****
else {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
! final FileInputStream fis = new FileInputStream(name);
! final PartialInputStream in = new PartialInputStream
! (fis, offset, length);
! final byte[] buffer = new byte[4096];
! for (int c=in.read(buffer) ; c!=-1 ; c=in.read(buffer))
! out.write(buffer, 0, c);
! return out.toByteArray();
}
}
--- 510,538 ----
else {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
! InputStream fis = null;
! try {
! if (dataSource != null) {
! fis = dataSource.getInputStream();
! } else {
! fis = new FileInputStream(name);
! }
! final PartialInputStream in = new PartialInputStream
! (fis, offset, length);
! final byte[] buffer = new byte[4096];
! for (int c=in.read(buffer) ; c!=-1 ; c=in.read(buffer))
! out.write(buffer, 0, c);
! return out.toByteArray();
! } catch (IOException e) {
! throw e;
! } finally {
! if (fis != null) {
! try {
! out.close();
! fis.close();
! } catch (IOException e) {
! throw e;
! }
! }
! }
}
}
Index: EbxmlMessage.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging/EbxmlMessage.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** EbxmlMessage.java 17 Nov 2003 02:09:33 -0000 1.37
--- EbxmlMessage.java 9 Dec 2003 08:59:10 -0000 1.38
***************
*** 1,84 ****
/*
! * Copyright(c) 2002 Center for E-Commerce Infrastructure Development, The
! * University of Hong Kong (HKU). All Rights Reserved.
*
! * This software is licensed under the Academic Free License Version 1.0
*
! * Academic Free License
! * Version 1.0
*
! * This Academic Free License applies to any software and associated
[...2215 lines suppressed...]
+ /**
+ * Sets the fileName attribute of the EbxmlMessage object
+ *
+ * @param filename The new fileName value
+ */
public void setFileName(String filename) {
this.filename = filename;
}
+ /**
+ * Gets the fileName attribute of the EbxmlMessage object
+ *
+ * @return The fileName value
+ */
public String getFileName() {
return filename;
}
}
+
Index: MessageHeader.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging/MessageHeader.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** MessageHeader.java 27 Jun 2003 01:44:58 -0000 1.13
--- MessageHeader.java 9 Dec 2003 08:59:10 -0000 1.14
***************
*** 865,869 ****
*
* @param conversationId Conversation ID of the message.
! * @exception SOAPException
*/
public void setConversationId(String conversationId)
--- 865,869 ----
*
* @param conversationId Conversation ID of the message.
! * @throws SOAPException
*/
public void setConversationId(String conversationId)
***************
*** 913,917 ****
*
* @param serviceName Service name.
! * @exception SOAPException
*/
public void setService(String serviceName) throws SOAPException {
--- 913,917 ----
*
* @param serviceName Service name.
! * @throws SOAPException
*/
public void setService(String serviceName) throws SOAPException {
***************
*** 974,978 ****
* Set optional "type" attribute in service element
*
! * @exception SOAPException
*/
public void setServiceType(String type) throws SOAPException {
--- 974,978 ----
* Set optional "type" attribute in service element
*
! * @throws SOAPException
*/
public void setServiceType(String type) throws SOAPException {
***************
*** 1006,1010 ****
*
* @param action Action name.
! * @exception SOAPException
*/
public void setAction(String action) throws SOAPException {
--- 1006,1010 ----
*
* @param action Action name.
! * @throws SOAPException
*/
public void setAction(String action) throws SOAPException {
***************
*** 1205,1209 ****
* set as TimeToLive value.
*
! * @exception SOAPException
*/
public void setTimeToLive(Date time)
--- 1205,1209 ----
* set as TimeToLive value.
*
! * @throws SOAPException
*/
public void setTimeToLive(Date time)
Index: MessageOrder.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging/MessageOrder.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** MessageOrder.java 9 Apr 2003 07:48:26 -0000 1.5
--- MessageOrder.java 9 Dec 2003 08:59:10 -0000 1.6
***************
*** 152,156 ****
* SequenceNumber element.
*
! * @exception SOAPException
*/
MessageOrder(SOAPEnvelope soapEnvelope, SOAPElement soapElement)
--- 152,156 ----
* SequenceNumber element.
*
! * @throws SOAPException
*/
MessageOrder(SOAPEnvelope soapEnvelope, SOAPElement soapElement)
Index: PartialInputStream.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging/PartialInputStream.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** PartialInputStream.java 9 Apr 2003 07:48:27 -0000 1.3
--- PartialInputStream.java 9 Dec 2003 08:59:10 -0000 1.4
***************
*** 1,74 ****
/*
! * Copyright(c) 2002 Center for E-Commerce Infrastructure Development, The
! * University of Hong Kong (HKU). All Rights Reserved.
*
! * This software is licensed under the Academic Free License Version 1.0
*
! * Academic Free License
! * Version 1.0
*
! * This Academic Free License applies to any software and associated
! * documentation (the "Software") whose owner (the "Licensor") has placed the
! * statement "Licensed under the Academic Free License Version 1.0" immediately
! * after the copyright notice that applies to the Software.
*
! * Permission is hereby granted, free of charge, to any person obtaining a copy
! * of the Software (1) to use, copy, modify, merge, publish, perform,
! * distribute, sublicense, and/or sell copies of the Software, and to permit
! * persons to whom the Software is furnished to do so, and (2) under patent
! * claims owned or controlled by the Licensor that are embodied in the Software
! * as furnished by the Licensor, to make, use, sell and offer for sale the
! * Software and derivative works thereof, subject to the following conditions:
*
! * - Redistributions of the Software in source code form must retain all
! * copyright notices in the Software as furnished by the Licensor, this list
! * of conditions, and the following disclaimers.
! * - Redistributions of the Software in executable form must reproduce all
! * copyright notices in the Software as furnished by the Licensor, this list
! * of conditions, and the following disclaimers in the documentation and/or
! * other materials provided with the distribution.
! * - Neither the names of Licensor, nor the names of any contributors to the
! * Software, nor any of their trademarks or service marks, may be used to
! * endorse or promote products derived from this Software without express
! * prior written permission of the Licensor.
*
! * DISCLAIMERS: LICENSOR WARRANTS THAT THE COPYRIGHT IN AND TO THE SOFTWARE IS
! * OWNED BY THE LICENSOR OR THAT THE SOFTWARE IS DISTRIBUTED BY LICENSOR UNDER
! * A VALID CURRENT LICENSE. EXCEPT AS EXPRESSLY STATED IN THE IMMEDIATELY
! * PRECEDING SENTENCE, THE SOFTWARE IS PROVIDED BY THE LICENSOR, CONTRIBUTORS
! * AND COPYRIGHT OWNERS "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
! * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
! * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
! * LICENSOR, CONTRIBUTORS OR COPYRIGHT OWNERS BE LIABLE FOR ANY CLAIM, DAMAGES
! * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
! * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE.
*
! * This license is Copyright (C) 2002 Lawrence E. Rosen. All rights reserved.
! * Permission is hereby granted to copy and distribute this license without
! * modification. This license may not be modified without the express written
! * permission of its copyright owner.
*/
!
! /* =====
*
! * $Header$
*
! * Code authored by:
*
! * cyng [2002-07-29]
*
! * Code reviewed by:
*
! * username [YYYY-MM-DD]
*
! * Remarks:
*
! * =====
*/
-
package hk.hku.cecid.phoenix.message.packaging;
import java.io.InputStream;
- import java.io.IOException;
/**
--- 1,73 ----
/*
! * Copyright(c) 2002 Center for E-Commerce Infrastructure Development, The
! * University of Hong Kong (HKU). All Rights Reserved.
*
! * This software is licensed under the Academic Free License Version 1.0
*
! * Academic Free License
! * Version 1.0
*
! * This Academic Free License applies to any software and associated
! * documentation (the "Software") whose owner (the "Licensor") has placed the
! * statement "Licensed under the Academic Free License Version 1.0" immediately
! * after the copyright notice that applies to the Software.
*
! * Permission is hereby granted, free of charge, to any person obtaining a copy
! * of the Software (1) to use, copy, modify, merge, publish, perform,
! * distribute, sublicense, and/or sell copies of the Software, and to permit
! * persons to whom the Software is furnished to do so, and (2) under patent
! * claims owned or controlled by the Licensor that are embodied in the Software
! * as furnished by the Licensor, to make, use, sell and offer for sale the
! * Software and derivative works thereof, subject to the following conditions:
*
! * - Redistributions of the Software in source code form must retain all
! * copyright notices in the Software as furnished by the Licensor, this list
! * of conditions, and the following disclaimers.
! * - Redistributions of the Software in executable form must reproduce all
! * copyright notices in the Software as furnished by the Licensor, this list
! * of conditions, and the following disclaimers in the documentation and/or
! * other materials provided with the distribution.
! * - Neither the names of Licensor, nor the names of any contributors to the
! * Software, nor any of their trademarks or service marks, may be used to
! * endorse or promote products derived from this Software without express
! * prior written permission of the Licensor.
*
! * DISCLAIMERS: LICENSOR WARRANTS THAT THE COPYRIGHT IN AND TO THE SOFTWARE IS
! * OWNED BY THE LICENSOR OR THAT THE SOFTWARE IS DISTRIBUTED BY LICENSOR UNDER
! * A VALID CURRENT LICENSE. EXCEPT AS EXPRESSLY STATED IN THE IMMEDIATELY
! * PRECEDING SENTENCE, THE SOFTWARE IS PROVIDED BY THE LICENSOR, CONTRIBUTORS
! * AND COPYRIGHT OWNERS "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
! * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
! * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
! * LICENSOR, CONTRIBUTORS OR COPYRIGHT OWNERS BE LIABLE FOR ANY CLAIM, DAMAGES
! * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
! * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE.
*
! * This license is Copyright (C) 2002 Lawrence E. Rosen. All rights reserved.
! * Permission is hereby granted to copy and distribute this license without
! * modification. This license may not be modified without the express written
! * permission of its copyright owner.
*/
! /*
! * =====
*
! * $Header$
*
! * Code authored by:
*
! * cyng [2002-07-29]
*
! * Code reviewed by:
*
! * username [YYYY-MM-DD]
*
! * Remarks:
*
! * =====
*/
package hk.hku.cecid.phoenix.message.packaging;
+ import java.io.IOException;
import java.io.InputStream;
/**
***************
*** 87,92 ****
private long currentRead;
PartialInputStream(InputStream in, long offset, long length)
! throws IOException {
this.in = in;
this.length = length;
--- 86,99 ----
private long currentRead;
+ /**
+ * Constructor for the PartialInputStream object
+ *
+ * @param in the origninal input stream
+ * @param offset the offset the read data from the stream.
+ * @param length the length of the data to be read
+ * @exception IOException Description of the Exception
+ */
PartialInputStream(InputStream in, long offset, long length)
! throws IOException {
this.in = in;
this.length = length;
***************
*** 102,109 ****
--- 109,127 ----
}
+ /**
+ * close the stream
+ *
+ * @exception IOException thrown when IO error occur during closing
+ */
public void close() throws IOException {
in.close();
}
+ /**
+ * read a byte from the stream
+ *
+ * @return the byte in int value from the stream.
+ * @exception IOException thrown when IO error occur during reading.
+ */
public int read() throws IOException {
if (currentRead < length) {
***************
*** 113,120 ****
}
return r;
! }
! else {
return -1;
}
}
}
--- 131,138 ----
}
return r;
! } else {
return -1;
}
}
}
+
|