Enlightensoft's Blog

Helping in your each step

  • Categories

  • Authors

Archive for the ‘Other’ Category

Eclipse PlugIn For SVN, FIND BUG, MAVEN, PMD & CheckStyle

Posted by Pankil Patel on May 15, 2012

Eclipse & Oracle Workshop for WebLogic Plug-In For SVN, FIND BUG, MAVEN, PMD & CheckStyle

CheckStyle: http://eclipse-cs.sf.net/update/

SVN: http://subclipse.tigris.org/update_1.0.x or http://subclipse.tigris.org/update_1.6.x or http://subclipse.tigris.org/update_1.8.x or http://subclipse.tigris.org/update_1.10.x

FIND BUG: http://findbugs.cs.umd.edu/eclipse

PMD: http://pmd.sourceforge.net/eclipse

MAVEN: http://m2eclipse.sonatype.org/sites/archives/m2e-0.10.0-20100209-0800/

Mule ESB: http://studio.mulesoft.org/3.4/plugin

Ref. URL: http://blogs.mulesoft.org/installing-mule-studio-3-4-via-update-site-or-eclipse-marketplace/comment-page-1/

Posted in IDE, Other | Leave a Comment »

Audio – wav to mp3, flv to wave, flv to mp3, wav to pm file conversion

Posted by Pankil Patel on August 30, 2010

/**
*          AudioUtils.java File
*/
package co.cc.enlightensoft.util;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* This utils class would provide all Audio operations like convert Flv To Mp3
* etc.
*
* @author Pankil Patel
*
*/
public class AudioUtils {

private static Log LOG = LogFactory.getLog(FileUtils.class);

/**
*
* @param directory
* @return
* @throws IOException
*/
public static boolean convertFlvToMp3(String flvFile, String mp3Folder,
String mp3FileName) throws IOException {
String cmd = “ffmpeg -title \”” + mp3FileName + “\” -i \”” + flvFile
+ “\” -acodec mp3 -ac 2 -ab 128 -vn -y \”” + mp3Folder
+ mp3FileName + “.mp3\””;
LOG.info(“converFlvToMp3 cmd: ” + cmd);
Runtime.getRuntime().exec(cmd.split(” “));
System.out.println(“converFlvToMp3: Done………………”);
// Runtime.getRuntime().exec(cmd.split(” “));
return true;
}

/**
*
* @param directory
* @return
* @throws IOException
*/
public static boolean convertFlvToWav(String flvNameFileWithFullPath,
String wavFileNameWithFullPath) throws IOException {
String cmd = “ffmpeg -i ” + flvNameFileWithFullPath + ” -y ”
+ wavFileNameWithFullPath;
LOG.info(“convertFlvToWav cmd: ” + cmd);
RuntimeUtils.executeCommand(cmd.split(” “));
System.out.println(“convertFlvToWav: Done………………”);
return true;
}

/**
*
* @param directory
* @return
* @throws IOException
*/
public static boolean convertWavToMP3(String wavNameFileWithFullPath,
String mp3FileNameWithFullPath) throws IOException {
String cmd = “lame -V2 ” + wavNameFileWithFullPath + ” ”
+ mp3FileNameWithFullPath;
LOG.info(“convertWavToMP3 cmd: ” + cmd);
RuntimeUtils.executeCommand(cmd.split(” “));
System.out.println(“convertWavToMP3: Done………………”);
return true;
}

/**
* @param wavFileFolderPath
* @param genderCommand
* @return
* @throws IOException
*/
public static boolean convertWavToPM(String wavFileFullPath,
String genderCommand, String pmGeneratorPath) throws IOException {
String cmd = pmGeneratorPath + genderCommand + ” ” + wavFileFullPath;
LOG.info(“convertWavToPM cmd: ” + cmd);
RuntimeUtils.executeCommand(cmd.split(” “));
System.out.println(“convertWavToPM: Done………………”);
return true;
}
}

/**
*         RuntimeUtils.java File
*/
package co.cc.enlightensoft.util;

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* @author Pankil Patel
*
*/
public class RuntimeUtils {
private static final Log LOG = LogFactory.getLog(RuntimeUtils.class);

/**
* Executes the given command and return the results as a list
*
* @param cmd
*            The command that is being executed.
* @return List The list of the out put
*/
public static List<String> executeCommand(String… cmd) {
Process process = null;
try {
process = Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
LOG.info(e.getMessage() + e);
e.printStackTrace();
}
BufferedReader localBufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String str;
ArrayList<String> localArrayList = null;
try {
str = localBufferedReader.readLine();

localArrayList = new ArrayList<String>();
while (str != null) {
localArrayList.add(str);
str = localBufferedReader.readLine();
}
} catch (IOException e) {
LOG.info(e.getMessage() + e);
e.printStackTrace();
}
return localArrayList;
}

/**
* Executes the given command and return the results as a list
*
* @param cmd
*            The command that is being executed.
* @return List The list of the out put
*/
public static List<String> executeCommand(String cmd) {
Process process = null;
try {
process = Runtime.getRuntime().exec(cmd);

try {// For Printing Error
process.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(
process.getErrorStream()));
String line = “”;
while ((line = buf.readLine()) != null) {
System.out.println(line);
}
} catch (InterruptedException e) {
LOG.info(e.getMessage() + e);
e.printStackTrace();
}

} catch (IOException e) {
LOG.info(e.getMessage() + e);
e.printStackTrace();
}
BufferedReader localBufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String str;
ArrayList<String> localArrayList = null;
try {
str = localBufferedReader.readLine();

localArrayList = new ArrayList<String>();
while (str != null) {
localArrayList.add(str);
str = localBufferedReader.readLine();
}
} catch (IOException e) {
LOG.info(e.getMessage() + e);
e.printStackTrace();
}
return localArrayList;
}
}

Posted in Core Java, Other | 1 Comment »

Upload file using single jsp code.

Posted by Pankil Patel on August 30, 2010

<!– upload.jsp –>
<%@ page import=”java.io.*”%>
<%
String bookId = “7”;
String param = request.getParameter(“eBookID”);
System.out.println(“Parameter :: ” + param);
if (param != null) {
bookId = param;
}

String contentType = request.getContentType();
System.out.println(“Content type is :: ” + contentType);
if ((contentType != null)
&& (contentType.indexOf(“multipart/form-data”) >= 0)) {
DataInputStream in = new DataInputStream(request
.getInputStream());

int formDataLength = request.getContentLength();

byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead,
formDataLength);
totalBytesRead += byteRead;
}

String file = new String(dataBytes);

String saveFile = file
.substring(file.indexOf(“filename=\””) + 10);
saveFile = saveFile.substring(0, saveFile.indexOf(“\n”));
saveFile = saveFile.substring(saveFile.lastIndexOf(“\\”) + 1,
saveFile.indexOf(“\””));

//out.print(dataBytes);

int lastIndex = contentType.lastIndexOf(“=”);
String boundary = contentType.substring(lastIndex + 1,
contentType.length());
//out.println(boundary);
int pos;
pos = file.indexOf(“filename=\””);

pos = file.indexOf(“\n”, pos) + 1;

pos = file.indexOf(“\n”, pos) + 1;

pos = file.indexOf(“\n”, pos) + 1;

int boundaryLocation = file.indexOf(boundary, pos) – 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;

File f = new File(“/opt/workspace/eBookStore/ebooks/” + bookId
+ “/assets/voiceprofiles/images/” + saveFile);
FileOutputStream fileOut = new FileOutputStream(f);
System.out.println(“File :: ” + f.getAbsolutePath());
//fileOut.write(dataBytes);
int len = endPos – startPos;
//if (len > dataBytes.length) {
len = dataBytes.length;
//}
System.out.println(dataBytes.length + ” # ” + startPos + ” # ”
+ endPos + ” @@@ ” + len);

fileOut.write(dataBytes, startPos, len – startPos);

fileOut.flush();
fileOut.close();

System.out.println(“File saved as ” + f.getAbsolutePath());

out.println(“File saved as ” + saveFile);

} else {
System.out.println(“sdfsdf “);
}
%>

<html>
<head>
<title>Upload page</title>
</head>
<body>
<form method=”post” ENCTYPE=’multipart/form-data’>

<input type=”file” name=”uploadfile”>

<input type=”submit” name=”Submit” value=”Submit”>
<input type=”reset” name=”Reset” value=”Reset”>
</form>
</body>
</html>

Posted in Other | Leave a Comment »

Get client IP address from JSP

Posted by Pankil Patel on March 30, 2010

<%
out.print( request.getRemoteAddr() );
out.print( request.getRemoteHost() );
%>

You may not get the real client IP if a the client is behind a proxy, you will get the IP of the proxy and not the client. However, the proxy may include the requesting client IP in a special HTTP header.

<%
out.print( request.getHeader("x-forwarded-for") );
%>

Posted in Other | 1 Comment »

GMAP – for: http://127.0.0.1:8080/

Posted by Pankil Patel on March 29, 2010

Your key is:
ABQIAAAACNDx0T0JXh8CN0jAb8VRvxTBfUk9TZrBRaIteybtnU2KziHEpRTJjJOCuE4Tp4T5LKk4IIuTqlx6rA

JavaScript Maps API Example

<script src=”http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true_or_false&amp;key=ABQIAAAACNDx0T0JXh8CN0jAb8VRvxTBfUk9TZrBRaIteybtnU2KziHEpRTJjJOCuE4Tp4T5LKk4IIuTqlx6rA” type=”text/javascript”></script>

http://code.google.com/apis/maps/faq.html#keysystem.

Sign-up URL: http://code.google.com/apis/maps/signup.html

Good Examples: http://www.codeproject.com/KB/scripting/Use_of_Google_Map.aspx

Posted in Other | Leave a Comment »

Gmap & JQuery

Posted by Pankil Patel on March 29, 2010

http://gmap.nurtext.de/examples.html

Posted in Other | Leave a Comment »

Servlet

Posted by Pankil Patel on March 26, 2010

package cc.co.enlightensoft.sample.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DownloadFileServlet extends HttpServlet {

public void destroy() {
super.destroy(); // Just puts “destroy” string in log
// Put your code here
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//File f = new File(“D:\\Personal Data\\Resumes\\Ajax-Basics.pdf”);
//String downloadFileName = request.getParameter(“file”);
//String filePath = HrmsCommonProperties.getPropertyValue(Constants.RESUME_LOCATION) + downloadFileName;
String filePath = request.getParameter(“file”);
//System.out.println(filePath);
File f = new File(filePath);
String fileName = f.getName().substring(
f.getName().lastIndexOf(“/”) + 1, f.getName().length());
if (f.exists() && f.canRead()) {
response.setHeader(“Content-Disposition”, “attachment; filename=”
+ fileName);
response.encodeRedirectURL(“Resume”);
String fileExtension = fileName
.substring(fileName.lastIndexOf(“.”) + 1);

response.setContentType(getMimeType(fileExtension));

try {
InputStream in = new FileInputStream(f);
BufferedInputStream stream = new BufferedInputStream(in);
ServletOutputStream outs = response.getOutputStream();

final int BUFFER_SIZE = 1024;

byte[] buffer = new byte[BUFFER_SIZE];
int readCount = -1;
while ((readCount = stream.read(buffer)) > 0) {
outs.write(buffer, 0, readCount);
}
outs.flush();
outs.close();
stream.close();
in.close();
} catch (Exception e) {
response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
out.println(“<script type=\”text/javascript\”>”);
out.println(“alert(\”Could not read requested file\”);”);
out.println(“this.window.close();”);
out.println(“</script>”);
}
} else {
response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
out.println(“<script type=\”text/javascript\”>”);
out.println(“alert(\”Requested file is not on Hard Disk\”);”);
out.println(“this.window.close();”);
out.println(“</script>”);
}
}

private String getMimeType(String fileExtension) {
if (fileExtension.equalsIgnoreCase(“doc”)) {
return “application/msword”;
}
if (fileExtension.equalsIgnoreCase(“txt”)) {
return “html/text”;
}
if (fileExtension.equalsIgnoreCase(“pdf”)) {
return “application/pdf”;
}
if (fileExtension.equalsIgnoreCase(“oda”)) {
return “application/oda”;
}
if (fileExtension.equalsIgnoreCase(“rtf”)) {
return “application/rtf”;
}
return “application/octet-stream”;
}

public void init() throws ServletException {
// Put your code here
}

}

Posted in Other | 2 Comments »