Skip to content

Instantly share code, notes, and snippets.

@sanaulla123
sanaulla123 / DirectoryFilterTest.java
Created July 19, 2012 18:29
Listing and filtering directory content
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class DirectoryFilterTest {
public static void main(String[] args) {
Path basePath = Paths.get("D:/tests");
public class Parser {
private Parser successor;
public void parse(String fileName){
if ( getSuccessor() != null ){
getSuccessor().parse(fileName);
}
else{
System.out.println("Unable to find the correct parser for the file: "+fileName);
public class TextParser extends Parser{
public TextParser(Parser successor){
this.setSuccessor(successor);
}
@Override
public void parse(String fileName) {
if ( canHandleFile(fileName, ".txt")){
System.out.println("A text parser is handling the file: "+fileName);
public class JsonParser extends Parser {
public JsonParser(Parser successor){
this.setSuccessor(successor);
}
@Override
public void parse(String fileName) {
if ( canHandleFile(fileName, ".json")){
System.out.println("A JSON parser is handling the file: "+fileName);
public class CsvParser extends Parser {
public CsvParser(Parser successor){
this.setSuccessor(successor);
}
@Override
public void parse(String fileName) {
if ( canHandleFile(fileName, ".csv")){
System.out.println("A CSV parser is handling the file: "+fileName);
public class XmlParser extends Parser {
@Override
public void parse(String fileName) {
if ( canHandleFile(fileName, ".xml")){
System.out.println("A XML parser is handling the file: "+fileName);
}
else{
super.parse(fileName);
}
import java.util.List;
import java.util.ArrayList;
public class ChainOfResponsibilityDemo {
/**
* @param args
*/
public static void main(String[] args) {
select
co.Code '_id',
co.Code 'code',
co.name 'name',
co.Continent 'continent',
co.region 'region',
co.SurfaceArea 'surface_area',
co.IndepYear 'year_of_independence',
co.Population 'population',
co.LifeExpectancy 'life_expectancy',
{
"type" : "jdbc",
"jdbc" : {
"password" : "******",
"user" : "root",
"url" : "jdbc:mysql://localhost:3306/world",
"sql" : [ {
"statement" : "world.sql"
} ],
@echo off
set DIR=%~dp0
set LIB=%DIR%..\lib\*
set BIN=%DIR%..\bin
REM ???
"%JAVA8_HOME%\bin\java" -cp "%LIB%" -Dlog4j.configurationFile="%BIN%\log4j2.xml" "org.xbib.tools.Runner" "org.xbib.tools.JDBCImporter" world-importer-config.json