I want to get the get the ContentResult from document which is in alfresco :
using this code
ContentResult contentResult = AlfrescoClientWS.getContentsById(docid,"HTTP://192.168.8.100:9080/alfresco/api",
GedListener.credentialUser, GedListener.credentialPwd);
I work in jboss 7.1 and I use this jar :
alfresco-web-service-client-4.0.d.jar,axis-1.4.jar,axis-saaj-1.2.jar,wsdl4j-1.6.2.jar,wss4j-1.5.4-patched.jar,xmlsec-1.4.1.jar
but when I test I have this error:
17:07:40,546 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myProject].[FileUploadServlet]] (http-localhost-127.0.0.1-8080-5) "Servlet.service()" pour la servlet FileUploadServlet a généré une exception: java.lang.NoSuchMethodError: org.apache.xml.security.transforms.Transform.init()V
at org.apache.ws.security.WSSConfig.staticInit(WSSConfig.java:244) [wss4j-1.5.4-patched.jar:]
at org.apache.ws.security.WSSConfig.<init>(WSSConfig.java:256) [wss4j-1.5.4-patched.jar:]
at org.apache.ws.security.WSSConfig.getNewInstance(WSSConfig.java:265) [wss4j-1.5.4-patched.jar:]
at org.apache.ws.security.handler.WSHandler.doSenderAction(WSHandler.java:89) [wss4j-1.5.4-patched.jar:]
at org.apache.ws.axis.security.WSDoAllSender.invoke(WSDoAllSender.java:170) [wss4j-1.5.4-patched.jar:]
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) [axis-1.4.jar:]
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) [axis-1.4.jar:]
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) [axis-1.4.jar:]
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:127) [axis-1.4.jar:]
at org.apache.axis.client.Call.invokeEngine(Call.java:2784) [axis-1.4.jar:]
at org.apache.axis.client.Call.invoke(Call.java:2767) [axis-1.4.jar:]
at org.apache.axis.client.Call.invoke(Call.java:2443) [axis-1.4.jar:]
at org.apache.axis.client.Call.invoke(Call.java:2366) [axis-1.4.jar:]
at org.apache.axis.client.Call.invoke(Call.java:1812) [axis-1.4.jar:]
at org.alfresco.webservice.content.ContentServiceSoapBindingStub.read(ContentServiceSoapBindingStub.java:467) [alfresco-web-service-client-4.0.d.jar:]
at com.dq.urbanplanning.web.ged.AlfrescoClientWS.getContentsById(AlfrescoClientWS.java:162) [classes:]
............
.........
I have this class java :AlfrescoClientWS.java
import org.alfresco.webservice.content.Content;
import org.alfresco.webservice.content.ContentFault;
import org.alfresco.webservice.content.ContentServiceSoapBindingStub;
import org.alfresco.webservice.repository.QueryResult;
import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
import org.alfresco.webservice.repository.UpdateResult;
import org.alfresco.webservice.types.CML;
import org.alfresco.webservice.types.CMLAddAspect;
import org.alfresco.webservice.types.CMLCreate;
import org.alfresco.webservice.types.ContentFormat;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.ParentReference;
import org.alfresco.webservice.types.Predicate;
import org.alfresco.webservice.types.Query;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.ResultSet;
import org.alfresco.webservice.types.ResultSetRow;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.ContentUtils;
import org.alfresco.webservice.util.Utils;
import org.alfresco.webservice.util.WebServiceFactory;
import org.apache.commons.io.IOUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import javax.activation.MimetypesFileTypeMap;
public class AlfrescoClientWS {
public static ContentResult getContentsById(String contentId, String cmurl, String userName, String pwd)
throws Exception {
ContentResult contentResult = new ContentResult();
// Start the session
WebServiceFactory.setEndpointAddress(cmurl);
AuthenticationUtils.startSession(userName, pwd);
try {
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
Reference contentReference = new Reference(storeRef, contentId, null);
Content[] readResult = null;
try {
readResult = contentService.read(new Predicate(new Reference[] { contentReference }, storeRef, null), Constants.PROP_CONTENT);
} catch (ContentFault e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
if ((readResult != null) && (readResult[0] != null)) {
Content content = readResult[0];
ContentFormat cnf = content.getFormat();
Reference ref = content.getNode();
String[] splitedUrl = content.getUrl().split("/");
String name = splitedUrl[splitedUrl.length - 1];
InputStream is = ContentUtils.getContentAsInputStream(content);
byte[] contentByte = IOUtils.toByteArray(is);
contentResult.setName(name);
contentResult.setMimetype(cnf.getMimetype());
contentResult.setId(ref.getUuid());
contentResult.setUrl(content.getUrl());
contentResult.setPath(ref.getPath());
contentResult.setContentByte(contentByte);
System.out.println(" document has been retrieved");
}
} catch (Exception e) {
System.out.println(e.toString());
} finally {
// End the session
AuthenticationUtils.endSession();
// System.exit(0);
}
return contentResult;
}
}
the error is related to this line :
readResult = contentService.read(new Predicate(new Reference[] { contentReference }, storeRef, null), Constants.PROP_CONTENT);
I test my code using Main class with this code :
import org.alfresco.webservice.content.Content;
import org.alfresco.webservice.content.ContentFault;
import org.alfresco.webservice.content.ContentServiceSoapBindingStub;
import org.alfresco.webservice.repository.QueryResult;
import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
import org.alfresco.webservice.repository.UpdateResult;
import org.alfresco.webservice.types.CML;
import org.alfresco.webservice.types.CMLAddAspect;
import org.alfresco.webservice.types.CMLCreate;
import org.alfresco.webservice.types.ContentFormat;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.ParentReference;
import org.alfresco.webservice.types.Predicate;
import org.alfresco.webservice.types.Query;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.ResultSet;
import org.alfresco.webservice.types.ResultSetRow;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.ContentUtils;
import org.alfresco.webservice.util.Utils;
import org.alfresco.webservice.util.WebServiceFactory;
import org.apache.commons.io.IOUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import javax.activation.MimetypesFileTypeMap;
public class AlfrescoClientWS {
public static void main(String[] args) {
try {
ContentResult contentResult =AlfrescoClientWS.getContentsById("85e686c6-aecd-4747-9f2e-56d8c58a3e08",
"HTTP://192.168.0.100:9080/alfresco/api", "admin", "12345");
System.out.println("-- contentResult:" + contentResult.getName());
} catch (Exception e) {
e.printStackTrace();
}
}
public static ContentResult getContentsById(String contentId, String cmurl, String userName, String pwd)
throws Exception {
ContentResult contentResult = new ContentResult();
// Start the session
WebServiceFactory.setEndpointAddress(cmurl);
AuthenticationUtils.startSession(userName, pwd);
try {
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
Reference contentReference = new Reference(storeRef, contentId, null);
Content[] readResult = null;
try {
readResult = contentService.read(new Predicate(new Reference[] { contentReference }, storeRef, null), Constants.PROP_CONTENT);
} catch (ContentFault e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
if ((readResult != null) && (readResult[0] != null)) {
Content content = readResult[0];
ContentFormat cnf = content.getFormat();
Reference ref = content.getNode();
String[] splitedUrl = content.getUrl().split("/");
String name = splitedUrl[splitedUrl.length - 1];
InputStream is = ContentUtils.getContentAsInputStream(content);
byte[] contentByte = IOUtils.toByteArray(is);
contentResult.setName(name);
contentResult.setMimetype(cnf.getMimetype());
contentResult.setId(ref.getUuid());
contentResult.setUrl(content.getUrl());
contentResult.setPath(ref.getPath());
contentResult.setContentByte(contentByte);
System.out.println(" document has been retrieved");
}
} catch (Exception e) {
System.out.println(e.toString());
} finally {
// End the session
AuthenticationUtils.endSession();
// System.exit(0);
}
return contentResult;
}
}
but when I test my code using jboss I have problem
Related
How do I stream each line to the Parser instance?
package net.bounceme.dur.files;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
public class StreamFile {
private final static Logger log = Logger.getLogger(StreamFile.class.getName());
private Parser p = new Parser();
public StreamFile() {
}
public void read(String filePath) {
Stream<String> stream = null;
try {
stream = Files.lines(Paths.get(filePath));
} catch (IOException ex) {
Logger.getLogger(StreamFile.class.getName()).log(Level.SEVERE, null, ex);
}
stream.forEach(System.out::println);
}
}
am working with a project in which I am trying to call a Servlet that will push XML message to a JMS queue running in my local machine, using java code. You can find the actual Servlet code below, which actually sends the message to the queue.
import java.io.IOException;
import java.io.PrintWriter;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MessageSender
extends HttpServlet
{
private static final long serialVersionUID = 1L;
static PrintWriter out;
public static final String CNN_FACTORY = "jms/alert/connectionFactory";
public static final String QUEUE_NAME = "jms/alert/amlScreenQueue";
public static String currentQueueName;
public static String JMSConnectionFactory;
private QueueConnection qcon;
private QueueSession qsession;
private static QueueSender qsender;
private Queue queue;
private static ObjectMessage om;
private static MessageProducer messageProducer;
public MessageSender() {}
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
try
{
String JMSQueueName = request.getParameter("JMSQueueName");
currentQueueName = JMSQueueName;
JMSConnectionFactory = request.getParameter("JMSConnectionFactory");
out = response.getWriter();
InitialContext ic = getInitialContext();
init(ic, JMSQueueName);
doPost(request, response);
}
catch (Exception e) {
e.printStackTrace();
}
}
public void init(Context ctx, String queueName)
throws NamingException, JMSException
{
QueueConnectionFactory qconFactory = (QueueConnectionFactory)ctx.lookup(JMSConnectionFactory);
this.qcon = qconFactory.createQueueConnection();
this.qsession = this.qcon.createQueueSession(false, 1);
queue = ((Queue)ctx.lookup(queueName));
QueueConnection qcon = qconFactory.createQueueConnection();
qcon.start();
QueueSession qsession = qcon.createQueueSession(false, 1);
qsender = qsession.createSender(queue);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String textMessage = request.getParameter("textMessage");
try
{
TextMessage msg = qsession.createTextMessage(textMessage);
msg.setStringProperty("JMSXGroupID", "1");
msg.setIntProperty("JMSXGroupSeq", 1);
msg.setBooleanProperty("JMS_IBM_Last_Msg_In_Group", false);
qsender.send(msg);
out.println("Message sent to queue " + currentQueueName);
out.println("");
out.println(msg.getText());
}
catch (JMSException e)
{
e.printStackTrace();
out.println(e.getErrorCode());
try
{
qsender.close();
qcon.close();
}
catch (JMSException e) {
e.printStackTrace();
}
}
finally
{
try
{
qsender.close();
qcon.close();
}
catch (JMSException e) {
e.printStackTrace();
}
}
}
private static InitialContext getInitialContext() throws NamingException
{
return new InitialContext();
}
}
This is the java code that I am using to call the servlet,
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map.Entry;
public class SendMessage {
public static void main(String[] args) throws URISyntaxException{
String line;
StringBuffer buffer = new StringBuffer();
String data = null;
try
{
String filePath = "data/payload.xml";
File dataFile = new File(filePath);
if(dataFile.exists()){
data = new String(Files.readAllBytes(Paths.get(filePath)));
}else{
System.out.println("Not Available");
}
String localUrl = "http://localhost:8080/SimulationTool/MessageSender";
String params = "JMSQueueName=jms/alert/amlScreenQueue&"
+ "JMSConnectionFactory=jms/alert/connectionFactory&"
+ "textMessage=" + data;
System.out.println("PARAMS:::" + params);
URL url = new URL(localUrl);
System.out.println("URL FOUND:::" + url.toURI());
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.connect();
System.out.println("Response Code:::" + ((HttpURLConnection)conn).getResponseCode());
BufferedWriter out = new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ));
out.write(params);
out.flush();
out.close();
// Response code
System.out.println("Response Code:::" + ((HttpURLConnection)conn).getResponseCode());
// Response values
for (Entry<String, List<String>> header : ((HttpURLConnection)conn).getHeaderFields().entrySet()) {
System.out.println(header.getKey() + "=" + header.getValue());
}
BufferedReader in = new BufferedReader( new InputStreamReader( conn.getInputStream() ) );
String response;
while ( (response = in.readLine()) != null ) {
System.out.println( response );
}
in.close();
}
catch ( MalformedURLException ex ) {
ex.printStackTrace();
}
catch ( IOException ex ) {
ex.printStackTrace();
}
}
}
The problem is its failing with below exception,
Response Code:::200
java.net.ProtocolException: Cannot write output after reading input.
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1312)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291)
at servlettests.SendMessage.main(SendMessage.java:63)
Its shows response code as 200, so the connection was successful but it fails while getting the outputstream, which is being created to send message to the queue. Pls help me on resolving this issue.
I am coding using Jira RestApi with Java and I am unable to complete the task. Can anyone help me to solve this? I am unable to call the rest api here
import static java.nio.charset.StandardCharsets.*;
package jira.rest.api;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.nio.charset.Charset;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import com.sun.jna.platform.win32.COM.TypeLibUtil.IsName;
public class JiraManager {
private final String m_BaseUrl = "http://localhost.:8080/rest/api/latest/";
private String m_Username;
private String m_Password;
public JiraManager(String username, String password) {
m_Username = username;
m_Password = password;
}
#SuppressWarnings("deprecation")
public void RunQuery() throws ClientProtocolException,
IOException {
String data = null;
String argument = null;
String method = "GET";
String url = String.format("{0}{1}/", m_BaseUrl, "project");
if (argument != null) {
url = String.format("{0}{1}/", url, argument);
}
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(m_BaseUrl);
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
private String GetEncodedCredentials() {
String mergedCredentials = String.format("{0}:{1}", m_Username,
m_Password);
byte[] byteCredentials = mergedCredentials.getBytes(Charset
.forName("UTF-8"));
String val = "";
try {
val = new String(byteCredentials, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return val;
}
}
My main class calls the rest api using the following code:
package jira.rest.api;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
public class main {
public main() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) throws ClientProtocolException,
IOException {
// TODO Auto-generated method stub
String username = "sbodhuluri";
String password = "Quad#2014";
JiraManager manager = new JiraManager(username, password);
manager.RunQuery();
System.out.println("Hello and welcome to a Jira Example application!");
}
}
I want to get all hyperlinks and name it as .txt file, and i want to store all paragraphs inside those each hyperlinks and save as a text file by their article title.
i have the code here and i am fixing this for 2 months. i could not get code for this crawling/scraping logic.
Anyone please code and fix it.
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.text.BadLocationException;
import javax.swing.text.EditorKit;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class App {
public static void main(String[] args) throws URISyntaxException,
IOException, BadLocationException {
HTMLDocument doc = new HTMLDocument() {
public HTMLEditorKit.ParserCallback getReader(int pos) {
return new HTMLEditorKit.ParserCallback() {
public void handleText(char[] data, int pos) {
System.out.println(data);
}
};
}
};
URL url = new URI("http://tamilblog.ishafoundation.org/").toURL();
URLConnection conn = url.openConnection();
Reader rd = new InputStreamReader(conn.getInputStream());
OutputStreamWriter writer = new OutputStreamWriter(
new FileOutputStream("ram.txt"), "UTF-8");
EditorKit kit = new HTMLEditorKit();
kit.read(rd, doc, 0);
try {
Document docs = Jsoup.connect(
"http://tamilblog.ishafoundation.org/").get();
Elements links = docs.select("a[href]");
Elements elements = docs.select("*");
System.out.println("Total Links :" + links.size());
for (Element element : elements) {
System.out.println(element.ownText());
}
for (Element link : links) {
String hrefUrl = link.attr("href");
if (!"#".equals(hrefUrl) && !hrefUrl.isEmpty()) {
System.out.println(" * a: link :" + hrefUrl);
System.out.println(" * a: text :" + link.text());
Document document = Jsoup.connect(hrefUrl)
.timeout(0) //Infinite timeout
.get();
String html = document.toString();
writer.write(html);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
writer.close();
}
}
}
Try something like this
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class NewClass {
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("http://tamilblog.ishafoundation.org").get();
Elements section = doc.select("section#content");
Elements article = section.select("article");
for (Element a : article) {
System.out.println("Title : \n" + a.select("a").text());
System.out.println("Article summary: \n" + a.select("div.entry-summary").text());
}
}
}
I want to create a Java application ( and then make it and applet to work on the web) that allows to upload a file to a remote server. The file has already been downloaded previously from the server. I have already have the code for the download part, but for the uploading I have the following code shown below..
The import libraries are fine but the issue is on the Uploader class that does throw me an error.. I think my BufferReader class is missing something but I need your help to debugging it...
UploadApplet.java
import com.leo.upload.BufferReader;
import com.leo.upload.Uploader;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Frame;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Properties;
import java.util.Random;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.LoggingPermission;
import java.util.logging.SimpleFormatter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JApplet;
import javax.swing.JPanel;
import netscape.javascript.JSObject;
public class UploadApplet extends JApplet {
public void start()
{
super.start();
uploadFile("/Users/XXXXX/Desktop/Tesing123.indd","http://xx.xx.xxx.xxx/");
}
public String uploadFile(String paramString1, String paramString2)
{
String str = "0";
try {
// I call the Uploader class to make the upload to the server
str = (String)AccessController.doPrivileged(new Uploader(paramString1, paramString2));
System.out.println(str);
}
catch (Exception e) {
e.printStackTrace();
}
return str;
}
Uploader.java
import com.leo.upload.BufferReader;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.security.PrivilegedAction;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class Uploader
implements PrivilegedAction<String>
{
private static final String a = Uploader.class.getName();
private Logger b = Logger.getLogger(a);
private String c;
private String d;
public Uploader(String paramString1, String paramString2)
{
this.c = paramString1;
this.d = paramString2;
}
public String run()
{
FileInputStream localFileInputStream = null;
BufferedInputStream localBufferedInputStream = null;
Writer localWriter = null;
InputStream localInputStream = null;
LineNumberReader localLineNumberReader = null;
Object localObject1 = "0";
try
{
File localFile = new File(this.c);
localFileInputStream = new FileInputStream(localFile);
localBufferedInputStream = new BufferedInputStream(localFileInputStream);
Object localObject2 = new URL(this.d);
URLConnection localURLConnection = ((URL)localObject2).openConnection();
localURLConnection.addRequestProperty("Filename", localFile.getName());
localURLConnection.setRequestProperty("Content-type", "application/binary");
long l = localFile.length();
Object localObject3;
if (l <= 2147483647L) {
if ((localURLConnection instanceof HttpURLConnection)) {
localObject3 = (HttpURLConnection)localURLConnection;
((HttpURLConnection)localObject3).setFixedLengthStreamingMode((int)localFile.length());
}
localURLConnection.setDoOutput(true);
**// I call the BufferReader class, and the a method to perform the writing**
BufferReader.a(localBufferedInputStream, localURLConnection.getOutputStream());
localInputStream = localURLConnection.getInputStream();
localLineNumberReader = new LineNumberReader(new InputStreamReader(localInputStream, "UTF8"));
localObject1 = localLineNumberReader.readLine();
}
else {
localObject3 = "An error occurred during file upload: Cannot upload a file larger than 2GB.";
JOptionPane.showMessageDialog(null, localObject3, "Error during file upload", 0);
this.b.severe((String)localObject3);
localObject1 = localObject3;
}
}
catch (Throwable localIOException4) {
localIOException4.printStackTrace();
Object localObject2 = "An error occurred during file upload: " + localIOException4.toString();
localObject1 = localObject2;
} finally {
BufferReader.a(localFileInputStream, localBufferedInputStream, localWriter);
if (localLineNumberReader != null) {
try {
localLineNumberReader.close();
} catch (IOException localIOException5) {
localIOException5.printStackTrace();
}
}
if (localInputStream != null) {
try {
localInputStream.close();
} catch (IOException localIOException6) {
localIOException6.printStackTrace();
}
}
}
return (String)(String)(String)localObject1;
}
}
BufferReader.java
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Writer;
import java.util.logging.Logger;
public final class BufferReader
{
private static Logger logthis = Logger.getLogger(BufferReader.class.getName());
public static void a(InputStream paramInputStream, OutputStream paramOutputStream)
throws IOException
{
byte[] arrayOfByte = new byte[4096];
int i = 0;
int j;
while ((j = paramInputStream.read(arrayOfByte)) != -1) {
paramOutputStream.write(arrayOfByte, 0, j);
i += j;
}
logthis.fine("CopyBytes : " + i);
}
public static void a(InputStream paramInputStream, FileOutputStream paramFileOutputStream, BufferedOutputStream paramBufferedOutputStream)
{
if (paramInputStream != null) {
try {
paramInputStream.close();
} catch (IOException localIOException1) {
localIOException1.printStackTrace();
}
}
if (paramFileOutputStream != null) {
try {
paramFileOutputStream.flush();
} catch (IOException localIOException2) {
localIOException2.printStackTrace();
}
}
if (paramBufferedOutputStream != null) {
try {
paramBufferedOutputStream.flush();
} catch (IOException localIOException3) {
localIOException3.printStackTrace();
}
}
if (paramFileOutputStream != null) {
try {
paramFileOutputStream.close();
} catch (IOException localIOException4) {
localIOException4.printStackTrace();
}
}
if (paramBufferedOutputStream != null)
try {
paramBufferedOutputStream.close();
} catch (IOException localIOException5) {
localIOException5.printStackTrace();
}
}
public static void a(InputStream paramInputStream, BufferedInputStream paramBufferedInputStream, Writer paramWriter)
{
if (paramBufferedInputStream != null)
try {
paramBufferedInputStream.close();
}
catch (IOException localIOException1)
{
}
if (paramInputStream != null)
try {
paramInputStream.close();
}
catch (IOException localIOException2)
{
}
if (paramWriter != null)
try {
paramWriter.close();
}
catch (IOException localIOException3)
{
}
}
public static String a(InputStream paramInputStream)
throws IOException
{
BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(paramInputStream, "UTF-8"));
StringBuilder localStringBuilder = new StringBuilder();
String str = null;
while ((str = localBufferedReader.readLine()) != null) {
localStringBuilder.append(str);
}
localBufferedReader.close();
return localStringBuilder.toString();
}
}
Bear in mind that unsigned applets aren't usually allowed to open connections to addresses that aren't their originating web server...unless you specify that applets can do whatever they want in the client's java control panel