Friday, June 25, 2010

Reading file from URL into byte array output stream

Here is code which reads file from URL and writes to ByteArrayOutPutStream

try
{
InputStream is = new URL("http://localhost:8080/pdf/test.pdf").openStream();
ByteArrayOutputStream outputDoc = new ByteArrayOutputStream();
byte buf[]=new byte[1024];
int len;
while((len=is.read(buf))>0)
{
outputDoc.write(buf,0, len);
}
outputDoc.close();
}
catch(Exception e) { e.printStackTrace(); }


Reading file from URL and writing to file

File file = new File("D:/test123.pdf"); FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream outBuf = new BufferedOutputStream(fos);
InputStream is = new URL("http://localhost:8080/pdf/test.pdf").openStream();
byte buf[]=new byte[1024]; int len; while((len=is.read(buf))>0) { outBuf.write(buf,0, len); } outBuf.close(); fos.close();

Thursday, March 11, 2010

Resolving java.lang.OutOfMemoryError: PermGen space in Weblogic

Hi,

To resolve the java.lang.OutOfMemoryError: PermGen space in Weblogic please add the following line

set USER_MEM_ARGS=-Xms512m -Xmx1024m -XX:MaxPermSize=128m

in :\Oracle\Middleware\user_projects\domains\dgmt_domain\bin\setDomainEnv.cmd

Thanks,


Enable Remote Debugging in Weblogic

Hi,

Remote debugging in Weblogic with Eclipse can be configured as follows:

In startWebLogic.cmd file, can be found at :\Oracle\Middleware\user_projects\domains\dgmt_domain\bin\startWebLogic.cmd,

Replace

set JAVA_OPTIONS =%SAVE_JAVA_OPTIONS%

With

set JAVA_OPTIONS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n %SAVE_JAVA_OPTIONS%

While starting the Weblogic you will see “Listening for transport dt_socket at address: 1044” then we are sure that debug is enabled on weblogic.

Thanks,


Tuesday, February 9, 2010

Spring MVC Training

Check out this SlideShare Presentation:

Thursday, October 22, 2009

Running your script at system startup on linux

Hi,

If you want to run your script at system startup e.g if you want to start jboss on system startup and stop on system shut down then create script and put it in "/etc/init.d" directory.

If you are using Debian then use 'update-rc.d' utility to install and remove System-V style init script links. Other distributions (such as Red Hat) use 'chkconfig'. You can see these utilities the you can locate files and check them.

If name of the script is say jboss then use following command

update-rc.d jboss defaults

If defaults is used, update-rc.d will make links to start the service in runlevels 2345, and stop the service in runlevels 016.

To start the script jboss in runlevels 0123 and stop in 456, run (as root):

update-rc.d jboss start 0123 stop 456

Read more: http://wiki.linuxquestions.org/wiki/Update-rc.d#ixzz0UjiBfsGM


For other distribution like red hat you can use chkconfig

Following tag needs to be added to your script so that it can be added to chkconfig
#!/bin/sh
#
# chkconfig: 2345 90 60

then you can add script by using command

chkconfig --add jboss

you can see all scripts configured by command

chkconfig --list

Regards,
Anand