Friday, January 4, 2013

ResourceBundle to Properties using Java

public Properties toProperties(ResourceBundle resourceBundle) {
Set keys = resourceBundle.keySet();
Properties properties = new Properties();
for (String key : keys) {
properties.put(key, resourceBundle.getString(key));
}
return properties;
}

Clob to String using Java

public String stringValue(Clob clob) {
BufferedReader br = null;
StringBuffer buffer = null;
try {
br = new BufferedReader(clob.getCharacterStream());
int c;
buffer = new StringBuffer();
while ((c = br.read()) != -1) {
buffer.append((char) c);
}
return buffer.toString();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null)
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return buffer.toString();
}

InputStream to String using Java

public String stringValue(InputStream inputStream) {
BufferedReader br = null;
StringBuffer buffer = null;
try {
br = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
buffer = new StringBuffer();
while ((line = br.readLine()) != null) {
buffer.append(line);
}
return buffer.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null)
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return buffer.toString();
}

Get all files and folders in FTP location

package test;

import java.io.IOException;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;

public class GetAllFTPFiles {
public void getAllFTPFiles(String remoteHostName, String username,
String password, String workingDirectory) {
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(remoteHostName);
ftpClient.login(username, password);
ftpClient.changeWorkingDirectory(workingDirectory);
getFTPFiles(ftpClient, "");
} catch (Throwable e) {
e.printStackTrace();
} finally {
try {
ftpClient.logout();
} catch (Exception e) {
e.printStackTrace();
}
try {
ftpClient.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}

private void getFTPFiles(FTPClient ftpClient, String path)
throws IOException {
FTPFile[] ftpFiles = ftpClient.listFiles(path);
if (ftpFiles == null) {
log("No FTP Files");
} else {
log("No. of FTP Files : " + ftpFiles.length);
}
for (FTPFile ftpFile : ftpFiles) {
if (ftpFile.isDirectory()) {
String newPath = (!path.equals("")) ? path + "/"
+ ftpFile.getName() : ftpFile.getName();
System.out.println(newPath);
getFTPFiles(ftpClient, newPath);
} else {
log(path + "/" + ftpFile.getName());
}
path = path.replaceAll(ftpFile.getName(), "");
}
}

private void log(Object log) {
System.out.println(log);
}
}

Friday, March 25, 2011

Java Ebooks

Core Java™ 2: Volume II–Advanced Features 5th Edition By Cay S. Horstmann, Gary Cornell COVERS J2SE VERSIONS 1.3/1.4 (2001) (1370 Pages)


Core Java™ 2: Volume II–Advanced Features 7th Edition By Cay S. Horstmann, Gary Cornell Chapter 1 Multithreading (84 Pages)


Core Java™ 2: Volume II–Advanced Features By Cay S. Horstmann, Gary Cornell Chapter 13 Annotation (13 Pages)


Java for Everyone, Cay Horstmann Chapter 12 Graphical User Interfaces (2010) (37 Pages)


Core Java™ 2: Volume I–Fundamentals 5th Edition By Cay S. Horstmann, Gary Cornell COVERS J2SE VERSION 1.3 (2000) (783 Pages)


Core Java™ 2: Volume I–Fundamentals 5th Edition By Cay S. Horstmann, Gary Cornell COVERS J2SE VERSION 1.3 (2000) (783 Pages)


Composition vs Inheritance Lawrence M. Brown (1 Page)


Core Java™ 2: Volume II–Advanced Features 8th Edition By Cay S. Horstmann, Gary Cornell (2006) (134 Pages)


Java Note (323 Pages)


Introduction to Object Oriented Programming (OOP) by Dr. Lyle N. Long (2008) (13 Pages)


Chapter 10 Deploying Applications and Applets (58 Pages)


Core Java, Volume 1-Fundamentals, Eighth Edition - Chapter 5 Inheritance (2007) (70 Pages)


Core Java™ 2: Volume II–Advanced Features 7th Edition By Cay S. Horstmann, Gary Cornell (2004) (1216 Pages)


Concurrent Object-Oriented Programming in JAVA By: Kaoutar El Maghraoui (2003) (14 Pages)


Client-Server Applications in Java by Jasmine J. Ahuja (1997) (37 Pages)


JSF and Struts Classic Reference Manual (2007) (38 Pages)


THE Java™ Programming Language, Fourth Edition By Ken Arnold, James Gosling, David Holmes (2005) (642 Pages)


Java™ Design Patterns: A Tutorial By James W. Cooper (2000) (278 Pages)


Effective Java: Programming Language Guide Joshua Bloch, Addison Wesley (2001) (180 Pages)


Java Collections by John Zukowski, Apress (2001) (295 Pages)


Design Patterns Java™ Workbook By Steven John Metsker, Addison Wesley (2002) (400 Pages)


The Java™ Language Specification Third Edition James Gosling, Bill Joy, Guy Steele, Gilad Bracha, ADDISON-WESLEY (2005) (684 Pages)


Thinking in Java Second Edition Bruce Eckel President, MindView, Inc. Prentice Hall, (2000) (1156 Pages)


SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065) Kathy Sierra, Bert Bates (2008) (890 Pages)


SCJP Sun Certified Programmer for Java® Platform, SE6 Study Guide Richard F. Raposa (2009) (583 Pages)


SCWCD – Study Guide (67 Pages)


Sun Certified Web Component Developer Study Guide - v2 (60 Pages)


SCWCD Exam Study Kit Second Edition JAVA WEB COMPONENT DEVELOPER CERTIFICATION MATTHEW SCARPINO (Second Edition author) HANUMANT DESHMUKH ,JIGNESH MALAVIA with Jacquelyn Carter MANNING (2005) (559 Pages)