2015-03-07

Read WebP images in Java


Read WebP images in Java
There is an open source package for WebP decoding. It can be used to read a WebP image with Java ImageIO. Unfortunately there is no encoder in this package, so we can not create a WebP image.

Download Webp Java Decoder WebPViewer-0.2.jar here.
http://sourceforge.net/projects/javavp8decoder/files/

Before using this Jar file, you should create a file named javax.imageio.spi.ImageReaderSpi under META-INF/services. There is only one line in this file:

net.sf.javavp8decoder.imageio.WebPImageReaderSpi

Put this file into the Jar file under the directory META-INF/services. Put the Jar file in the CLASSPATH. Then done!

ImageIO will load the Reader automatically. The file extension name of WebP image is .webp.

Labels: , ,

Create an EBS Volume and attach it to an EC2 instance

Create an EBS Volume and attach it to an EC2 instance

In the control console, Volumes of ELASTIC BLOCK STORE in the left menu. Click Create Volume. Fill the forms, and select Availability Zone where your instance is located. Then click Yes, Create. In the list, you can see the volume you just create. Assign a name to it for easy to remember.
 
In the popup list, select Attach Volume to attach this volume to your instance. Note that, you can assign a device name, but for the current new Linux kernel, the name will be renamed to /dev/xvd?.
 
Login to your instance. Find the name of the device ls -l /dev/xvd? , for example, it is /dev/xvdj. This is the new device.
 
Now, you should format it and mount it to a directory.
 
Format it in ext3:
# mkfs.ext3 /dev/xvdj
 
Mount it to a directory:
# mkdir /mnt/mydir
# mount /dev/xvdj /mnt/mydir
 
If you can not use df to list device, try following to create mtab:
# grep -v rootfs /proc/mounts > /etc/mtab
# df
 
Detach Volume or Force Detach Volume. It seems that the device is not removed from the instnace.
 
Sometimes the volume stays in Attaching or Detaching state for a long time. You have to Force Detach Valume and restart the instance. It seems that you can not really detach a volume from an instance. You have to manually unmont the device from the instance.
 

Labels:

Install Socks5 Proxy in Linux

Install Socks5 Proxy in Linux

Install Socks5 Proxy in Linux
1. Environment
Linux, gcc, yum.
 
2. Install Socks5.
Download http://sourceforge.net/projects/ss5/files/
ss5-3.8.9-8.tar.gz
 
# gunzip ss5-3.8.9-8.tar.gz
# tar xvf ss5-3.8.9-8.tar
 
Download some related pacakges:
#yum -y install pam-devel openssl-devel openldap-devel

3. Build
# ./configure
 
Compile.
# make
# make install

4. Configure
 
4.1 Modify /etc/opt/ss5/ss5.conf
No authentication
auth      0.0.0.0/0       -         -
User authentication
auth      0.0.0.0/0       -         u
permit u        0.0.0.0/0       -       0.0.0.0/0       -       -       -       -       -
 
4.2 Uncomment following line in /etc/sysconfig/ss5
SS5_OPTS=” -u root”
 
4.3 Modify port, defuat 1080
Modify /etc/rc.d/init.d/ss5
daemon /usr/sbin/ss5 -t $SS5_OPTS -b 0.0.0.0:10888
 
4.4 Add user and password.
Modify /etc/opt/ss5/ss5.passwd
# cat ss5.passwd
test 123
test2 123
 
4.5 Add auto-start
# chkconfig --add ss5
# chkconfig --level 345 ss5 on
 
4.6 Change ss5 executable
# chmod 700 /etc/rc.d/init.d/ss5
 
4.7 Set log file for ss5
When get error: Starting ss5... [ERRO] Error opening log file$
# export SS5_LOG_FILE=/var/log/ss5.log
This line can be added in script /etc/rc.d/init.d/ss5
 
4.8 Restart service
# /etc/rc.d/init.d/ss5 restart
 
5. Verify
Use QQ to verify the service.
 
6. Package compiled binary
Copy following files and put them into a tar file.
/etc/opt/ss5/
/etc/opt/ss5/ss5.passwd
/etc/opt/ss5/ss5.conf
/etc/opt/ss5/ss5.ha
/etc/rc.d/init.d/ss5
/etc/sysconfig/ss5
/usr/lib/ss5/
/usr/lib/ss5/mod_proxy.so
/usr/lib/ss5/mod_authentication.so
/usr/lib/ss5/mod_filter.so
/usr/lib/ss5/mod_socks5.so
/usr/lib/ss5/mod_log.so
/usr/lib/ss5/mod_statistics.so
/usr/lib/ss5/balamgr.cgi
/usr/lib/ss5/statmgr.cgi
/usr/lib/ss5/mod_authorization.so
/usr/lib/ss5/mod_balance.so
/usr/lib/ss5/mod_bandwidth.so
/usr/lib/ss5/SS5Logo.jpg
/usr/lib/ss5/mod_socks4.so
/usr/lib/ss5/mod_dump.so
/usr/sbin/ss5
/var/run/ss5

Labels:

jri.dll depends R.dll and JVM.dll

jri.dll depends R.dll and JVM.dll

When I run an application related to jri.dll, I got following exception:
 
2014-11-08 10:51:12,189 ERROR [STDERR] Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
2014-11-08 10:51:12,298 ERROR [STDERR] java.lang.UnsatisfiedLinkError: D:\thirdparty\R-3.1.1\library\rJava\jri\jri.dll: Can't find dependent libraries
 
D:\thirdparty\R-3.1.1\library\rJava\jri is already in PATH before starting the application. Something must be wrong while loading a DLL.
 
There is a simple way to check if the %PATH% is ready to load a DLL. It is a Windows command "regsvr32 dllname". Run this command and there may be some results:
 
1. Failed to load this DLL, and it is not found. The DLL does not exist, or any dependent DLLs do not exist.
 
2. DLL is loaded, but not registered. The DLL is a valid file, but not for a service.
 
3. DLL is not a valid Windows file. It is not a DLL, or a DLL for 64bit environment.
 
Actually jrl.dll depends on R.dll and JVM.dll. It is not smart to search in in subdirectories of R_HOME and JAVA_HOME. The real location of R.dll should be put into PATH before starting the application. JVM.dll is loaded internally by JVM process.
 

Labels: