package com.mp.ws;
/**
*
* @author nitinaggarwal
*
*/
public interface IFileUpload {public byte[] get1File(String name);
public byte[][] getMulitpleFiles(String names[]);
public String getXmlFile(String name);
}
package com.mp.ws;
/**
*
* @author nitinaggarwal
*
*/
public class FileUpload implements IFileUpload {public byte[] get1File(String name) {
byte data[] = null;FileReader fr = new FileReader();
try {
data = fr.readBinFilePath(name);
} catch (Exception e) {
e.printStackTrace();
}return data;
}public String getXmlFile(String name) {
String data = null;
FileReader fr = new FileReader();
try {
data = fr.readTextFile(name);
} catch (Exception e) {
e.printStackTrace();
}
return data;
}public byte[][] getMulitpleFiles(String[] fnames) {
byte[][] data = new byte[fnames.length][];
for (int i = 0; i < fnames.length; i++) {
FileReader fr = new FileReader();
try {
data[i] = fr.readBinFilePath(fnames[i]);System.out.println("abc" + data[i]);
} catch (Exception e) {
e.printStackTrace();
}
}
return data;
}}
package com.mp.ws;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;/**
*
* @author nitinaggarwal
*
*/
public class FileReader {public String readTextFile(final String name) throws Exception {
StringBuffer xmlFromFile = new StringBuffer();
InputStream instr = null;
//instr = getFilePath2(name);instr = new FileInputStream(name);
if (instr == null)
throw new FileNotFoundException();
InputStreamReader streamreader = null;try {
streamreader = new InputStreamReader(instr);
int x = 0;
x = streamreader.read();while (x != -1) {
xmlFromFile.append((char) x);
x = streamreader.read();}
} catch (Exception e) {
System.out.println("Exception " + e.getMessage());
throw e;} finally {
streamreader.close();}
return xmlFromFile.toString();
}
public byte[] readBinFileFromClassPath(final String name) throws Exception {
byte bytearray[] = null;
FileInputStream fileinputstream = null;
try {fileinputstream = new FileInputStream(getFilePath(name));
int numberBytes = fileinputstream.available();
bytearray = new byte[numberBytes];
fileinputstream.read(bytearray);} catch (Exception e) {
System.out.println("Exception " + e.getMessage());
throw e;} finally {
if (fileinputstream != null)
fileinputstream.close();
}return bytearray;
}public byte[] readBinFilePath(final String name) throws Exception {
byte bytearray[] = null;
FileInputStream fileinputstream = null;
try {fileinputstream = new FileInputStream(name);
int numberBytes = fileinputstream.available();
bytearray = new byte[numberBytes];
fileinputstream.read(bytearray);} catch (Exception e) {
System.out.println("Exception " + e.getMessage());
throw e;} finally {
if (fileinputstream != null)
fileinputstream.close();
}return bytearray;
}public void writeBinFileToPath(String name, byte data[]) throws IOException {
FileOutputStream fileoutputstream = new FileOutputStream(name);
try {
fileoutputstream.write(data);} catch (IOException e) {
System.out.println(e.getMessage());} finally {
if (fileoutputstream != null)
fileoutputstream.close();
data = null;
}}
private InputStream getFilePath2(String filename) {
return this.getClass().getClassLoader().getResourceAsStream(filename);}
private String getFilePath(String filename) throws FileNotFoundException {
String path = this.getClass().getClassLoader().getResource(filename)
.getPath();
if ("".equals(path))
throw new FileNotFoundException();
return path;}
}
package com.mp.ws;
/**
*
* @author nitinaggarwal
*
*/
@javax.jws.WebService(targetNamespace = "http://ws.mp.com/", serviceName = "FileUploadService", portName = "FileUploadPort")
public class FileUploadDelegate {com.mp.ws.FileUpload fileUpload = new com.mp.ws.FileUpload();
public byte[] get1File(String name) {
return fileUpload.get1File(name);
}public byte[][] getMulitpleFiles(String[] fnames) {
return fileUpload.getMulitpleFiles(fnames);
}public String getXmlFile(String name) {
return fileUpload.getXmlFile(name);
}}
package com.mp.ws;
/**
*
* @author nitinaggarwal
*
*/
public class FileUploadTester {public static void main(String[] args) {
FileUpload fu = new FileUpload();
String fnames[]= {"c:/uploadme.doc","c:/uploadme.doc","c:/uploadme.doc"};byte[][] data = fu.getMulitpleFiles(fnames);
}
}
Related
2 Responses so far.
Recent Posts
- 12.1.0.2 RAC Installation – Step by Step installation on VMware
- OSB FTP Poller continuously throwing exception – while no file pending on FTP Location
- Using JMS Transport with OSB
- Installing Spring Tool Suite and configuring Spring for a development PC
- Rest Enabling SOA using OSB in Oracle 12c
Recent Comments
- Nits on Installing Oracle SOA Suite 12c
- Rajesh Krishna on Installing Oracle SOA Suite 12c
- Nits on Installing Oracle SOA Suite 12c
- Rohinii on Installing Oracle SOA Suite 12c
- Mahitha on Oracle Service Bus (OSB) Development Best Practices.
Archives
- December 2015
- May 2015
- November 2014
- September 2014
- August 2014
- July 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- July 2013
- June 2013
- May 2013
- March 2013
- February 2013
- November 2012
- October 2012
- September 2012
- May 2012
- March 2012
- February 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- June 2011
- May 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- July 2010
- June 2010
- March 2010
- February 2010
- December 2009
- September 2009
- August 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- November 2008
- October 2008
- August 2008
- June 2008
- May 2008
Categories
- AIA
- AXIS2
- Best Practices
- BPEL
- BPM
- Budget
- Build
- Design Patterns
- ESB
- Hermes
- Hibernate
- Home Owners
- Java
- JMS
- JSR 168
- Maven
- Mediator
- Messaging
- Nitin
- OER
- OESB
- Oracle
- OSB
- OWSM
- Portlets
- SDLC
- Sequencing
- Singleton
- SOA
- SOAP
- Spring
- Struts
- UK
- Uncategorized
- Web Services
- WLST
Meta
To find out more, including how to control cookies, see here: Cookie Policy
Recent Posts
- 12.1.0.2 RAC Installation – Step by Step installation on VMware
- OSB FTP Poller continuously throwing exception – while no file pending on FTP Location
- Using JMS Transport with OSB
- Installing Spring Tool Suite and configuring Spring for a development PC
- Rest Enabling SOA using OSB in Oracle 12c
Recent Comments
- Nits on Installing Oracle SOA Suite 12c
- Rajesh Krishna on Installing Oracle SOA Suite 12c
- Nits on Installing Oracle SOA Suite 12c
- Rohinii on Installing Oracle SOA Suite 12c
- Mahitha on Oracle Service Bus (OSB) Development Best Practices.
Archives
- December 2015
- May 2015
- November 2014
- September 2014
- August 2014
- July 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- July 2013
- June 2013
- May 2013
- March 2013
- February 2013
- November 2012
- October 2012
- September 2012
- May 2012
- March 2012
- February 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- June 2011
- May 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- July 2010
- June 2010
- March 2010
- February 2010
- December 2009
- September 2009
- August 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- November 2008
- October 2008
- August 2008
- June 2008
- May 2008
Categories
- AIA
- AXIS2
- Best Practices
- BPEL
- BPM
- Budget
- Build
- Design Patterns
- ESB
- Hermes
- Hibernate
- Home Owners
- Java
- JMS
- JSR 168
- Maven
- Mediator
- Messaging
- Nitin
- OER
- OESB
- Oracle
- OSB
- OWSM
- Portlets
- SDLC
- Sequencing
- Singleton
- SOA
- SOAP
- Spring
- Struts
- UK
- Uncategorized
- Web Services
- WLST
thanks for this but i expecting like image file should be upload with single upload click and select multiple files are images and they should be upload to database or store in a floder.
TimlDK comment4 ,