Recent Notes
Displaying keyword search results 101 - 110
Created by Dr. Xi on August 27, 2010 22:35:53
Last update: August 27, 2010 22:35:53
This example decompresses a gzip compressed file with java.util.zip.GZIPInputStream . The input is assumed to be Base64 encoded after being gzipped (such would be the case when binary data is transmitted within an XML file).
You don't need the Base64InputStream if the data is not Base64 encoded.
import java.io.*;
import java.util.zip.GZIPInpu...
Created by Dr. Xi on August 24, 2010 21:59:22
Last update: August 24, 2010 21:59:22
This class decodes a Base64 encoded file with the Apache commons codec package:
import java.io.*;
import org.apache.commons.cod...
Created by Fang on August 23, 2010 22:55:58
Last update: August 24, 2010 15:45:04
The tags XML flow control tags are exactly the same as their Core flow control equivalents, except that the test condition with a boolean EL expression is replaced by the select condition with an XPath expression. In the case of the forEach tag, the items attribute is replaced with the select attribute. In a test condition, the XPath expression is evaluated to a boolean value by the rules of the XPath boolean() function, which converts its argument to a boolean as follows: a number is true if and only if it is neither positive or negative zero nor NaN. a node-set is true if and only if it is non-empty. a string is true if and only if its length is non-zero. an object of...
Created by Fang on August 17, 2010 19:27:32
Last update: August 17, 2010 19:27:32
Get the length of a collection The length function returns the size of a collection. It can be applied to any object supported by the JSTL core tag <c:forEach> , namely: Arrays Implementation of java.util.Collection Implementation of java.util.Iterator Implementation of java.util.Enumeration Implementation of java.util.Map String When used on String , it returns the number of characters in the string. Test it Make these additions to the expanded test application : Create a new Java class LengthFunction :
package jstl.demo.handler; import java.... Create a new JSP ( lengthfunction.jsp ) under webapp : <%@ taglib uri="http://java.sun.com/jsp/jstl/c... Compile and package the WAR with: mvn package Deploy the WAR to a servlet container of your choice (for example, Tomcat or JBoss). Test the page with this URL...
Created by nogeek on August 05, 2010 15:13:24
Last update: August 05, 2010 15:13:24
Read from stdio and print out rot13:
import java.io.BufferedReader;
import java.io.I...
The ROT13 translated Fourth Amendment reads:
Gur evtug bs gur crbcyr gb or frpher va gurve crefbaf, ubhfrf, cncref, naq rssrpgf, ntnvafg haernfbanoyr frnepurf naq frvmherf, funyy abg or ivbyngrq, naq ab Jneenagf funyy vffhr, ohg hcba cebonoyr pnhfr, fhccbegrq ol Bngu be nssvezngvba, naq cnegvphyneyl qrfpevovat gur cynpr gb or frnepurq, naq gur crefbaf be guvatf gb or frvmrq.
Created by Dr. Xi on August 03, 2010 16:29:35
Last update: August 03, 2010 16:36:50
This utility converts unicode escape strings in a file to UTF-8 encoded. Suppose you received a properties file with contents like:
# @(#)codepoint_zh_CN.properties 1.4 05/09/27
#...
You can use this utility to convert it to UTF-8 and view or edit.
import java.io.*;
/**
* Reads file with...
This utility is equivalent to:
native2ascii -reverse -encoding utf-8
using the standard Java native2ascii utility.
Created by voodoo on July 30, 2010 14:53:33
Last update: July 30, 2010 14:54:52
The -d switch for cURL sends HTTP POST with data from the command line. To verify the data being posted, this is a CGI script that echos the data back:
#!C:/perl/bin/perl.exe ## ## echo -- echos ... Examples: POST data from command line: C:\>curl -d input1=value1^&input1=value2 http://lo... POST data from stdin (with @ before the - symbol): C:\>curl -d @- http://localhost/cgi-bin/echo.pl ... POST data from a file (with @ before the - symbol and input redirect): C:\tmp>cat data.txt abcd 1234 xyz ... For some reason, @ with file name didn't work as expected: C:\tmp>curl -d @data.txt http://localhost/cgi-bin/... One thing to notice is that cURL removes the new line characters when posting (thus the echo back is only one line instead of three). This can...
Created by voodoo on July 11, 2009 15:14:55
Last update: July 29, 2010 22:45:48
cURL is a command line tool for transferring files with URL syntax. The main purpose and use for cURL is to automate unattended file transfers or sequences of operations.
It's really easy to see HTTP headers with curl:
C:\>curl --head http://www.google.com
HTTP/1.0 ...
or, headers and page together (dump headers to stdout):
$ curl --dump-header - http://www.google.com HTTP/...
Download openssl from openssl.org:
curl http://www.openssl.org/source/openssl-0.9.6m....
C:\>curl --help
Usage: curl [options...] <url>
...
Created by Dr. Xi on July 19, 2010 21:58:34
Last update: July 23, 2010 21:37:23
Parsing XML in Java is really simple:
import java.io.*; import javax.xml.parsers.Docu... The parser implementation details are hidden behind the JAXP API. In case you want to know which parser implementation is used, this is what the JavaDoc for DocumentBuilderFactory.newInstance says: Use the javax.xml.parsers.DocumentBuilderFactory system property. Use the properties file " lib/jaxp.properties " in the JRE directory. This configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above. The jaxp.properties file is read only once by the JAXP implementation and it's values are then cached for future use. If the file does not exist when the first attempt is made to read from it, no further attempts are made to...
Created by James on June 29, 2010 19:11:54
Last update: July 23, 2010 21:23:24
import java.util.Random;
public class Gener...