InputStream to String

0

Posted by Jagadeesh VP | Posted in ,


import java.io.InputStream;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class StreamToString {

public static void main(String[] args) throws Exception {
StreamToString sts = new StreamToString();

InputStream is = sts.getClass().getResourceAsStream("/data.txt");

/*
* Call the method to convert the
* stream to string
*/
System.out.println(sts.convertStreamToString(is));
}

public String convertStreamToString(InputStream is) throws IOException {
/*
* To convert the InputStream to String
* we use the BufferedReader.readLine()
* method. Each line will appended to a
* StringBuilder and returned as String.
*/
if (is != null) {
StringBuilder sb = new StringBuilder();
String line = null;

try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((line = reader.readLine()) != null)
sb.append(line).append("\n");

} catch (Exception e) {
//Do something..
} finally {
is.close();
}
return sb.toString();
} else {
return "";
}
}
}

GWT Startup

0

Posted by Jagadeesh VP | Posted in




Gwt [Server & Client Side] :

Models :

Pojos with Serializable implementation


RPC :


RemoteInterface --> Class extends the com.google.gwt.user.client.rpc.RemoteService
RemoteAsynInterface --> Class [RemoteIntefaceName]+"Async"
All the methods in RemoteInterface should defined in this interface with an extra parameter AsyncCallback.


Server : [ServerClass]


Class should implement RemoteInterface and extends com.google.gwt.user.server.rpc.RemoteServiceServlet


web.xml :


Tells the default page.
Also ServletClass & Mapping.

CallBack: [CallbackClass]


This the the class responsible for AJAX type updates to clients from Server (i.e., ServerClass)
CallbackClass Should implements com.google.gwt.user.client.rpc.AsyncCallback
Two methods:
public void onSuccess(T resultToClient)
The interface is parametrized, thus it supports strong typing. We can proceed with logic instead of worrying about type-casting.
public void onFailure(Throwable exception);


Client:


Probably like a Backing-Bean which has all the component's reference/Object that our page should have.
It should implement com.google.gwt.core.client.EntryPoint
This EntryPoint has the method onLoadModule()
We can override this method to load components in our page.



Project XML : [Project_Name.gwt.xml]


Specifies the compiler which is the Entry_point class.
It also specifies the name of other applications [via tag] in the same container, to which this application has the access.
It also has the URL - Servlet Mapping [As in struts-config file], to which URL which servlet/class is invoked.

[Typically like a WSDL file, since this also the remote call]



HTML Page:


GWT will generate this file, no need to take care on this.