Play sound(wav audio) in Java
Just for fun or for some application need, java provides functionality to play audio file. This is inbuilt in java and do not need any additional library. Following is simple code to play an wav file in java.
Information about technology, IT, gadget & computer
Just for fun or for some application need, java provides functionality to play audio file. This is inbuilt in java and do not need any additional library. Following is simple code to play an wav file in java.
package play_audio;
import java.io.File;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
/**
*
* @author Yusata Infotech
*/
public class play_audio {
public static void main(String[] args) {
try {
System.out.println("Start");
File f = new File("d://wavs//beep-1.wav");
AudioInputStream audio = AudioSystem.getAudioInputStream(f);
AudioFormat format;
format = audio.getFormat();
SourceDataLine auline;
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
auline = (SourceDataLine) AudioSystem.getLine(info);
auline.open(format);
auline.start();
int nBytesRead = 0;
byte[] abData = new byte[524288];
while (nBytesRead != -1) {
nBytesRead = audio.read(abData, 0, abData.length);
if (nBytesRead >= 0) {
auline.write(abData, 0, nBytesRead);
}
}
} catch (Exception E) {
System.out.println(E.getMessage());
}
}
}
A barcode is an optical machine-readable representation of data. The data which it represents, can be get back by machine reading it. Originally barcodes represented data by varying the widths and spacing of parallel lines, and may be referred to as linear or 1D barcode. Today there are number of barcodes used for many a purposes.
In Java, we may need to generate a barcode for some particular string. The generated barcode can be used for printing labels etc. Following is an example of generating barcode from java using ZXing api of google. It is open source api which can be used for generating barcodes for several types. Following is simple java program to generate various barcode(code128, QRCode and pdf417(Mostly used on drivers license in USA)) using ZXing.
package barcode;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Writer;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.oned.Code128Writer;
import com.google.zxing.pdf417.encoder.PDF417Writer;
import com.google.zxing.qrcode.QRCodeWriter;
import java.io.File;
import java.io.FileOutputStream;
/**
*
* @author Yusata Infotech
*/
public class Barcode {
public static void main(String[] args) {
BitMatrix bitMatrix;
Writer writer = new QRCodeWriter();
try {
// Write Barcode
bitMatrix = new Code128Writer().encode("123456789", BarcodeFormat.CODE_128, 150, 80, null);
MatrixToImageWriter.writeToStream(bitMatrix, "png", new FileOutputStream(new File("D://code128_123456789.png")));
System.out.println("Code128 Barcode Generated.");
// Write QR Code
bitMatrix = writer.encode("123456789", BarcodeFormat.QR_CODE, 200, 200);
MatrixToImageWriter.writeToStream(bitMatrix, "png", new FileOutputStream(new File("D://qrcode_123456789.png")));
System.out.println("QR Code Generated.");
// Write PDF417
writer = new PDF417Writer();
bitMatrix = writer.encode("123456789", BarcodeFormat.PDF_417, 80, 150);
MatrixToImageWriter.writeToStream(bitMatrix, "png", new FileOutputStream(new File("D://pdf417_123456789.png")));
System.out.println("PDF417 Code Generated.");
} catch (Exception e) {
System.out.println("Exception Found." + e.getMessage());
}
}
}
QRCode
Code128
PDF417
Download ZXing Library here
Multi-Level-Marketing (MLM) |
Work Nature | Online Data Entry on Portal |
Input Type | PDF / TIFF / JPG / GIF |
TAT | 25 days |
QC Report | 10 days after TAT |
Payment | Within 5 days of QC Report |
Payout | Rs.7 per form |
Workload | 6500 forms per system / TAT |
Registration Fee | Rs.12000.00 per system |
Website setup & Training | Rs.500 per system |
Agreement Type & Period | SLA for 11 months |
Accuracy Required | 90.1% minimum required for payment eligibility |
Payment Terms | 98.1% to 100% = Full payment 95.1% to 98% = 60% payment 90.1% to 95% = 30% payment Below 90.1% = No Rework / No Payment |
Technical Requirements | Windows OS(XP or 7) / Adobe reader / Image Viewer Internet connection / Google Chrome Browser |
Payment Mode | Cheque / Wire Transfer / DD |
Royalty | NIL |
Required Documents | Company Profile and LOI with Registration Payment |
Signup Procedure | Direct or Online Signup 7 days to start live after signup |
Author: Ashish Garg
OGNL(Object-Graph Navigation language) is an expression language inherited by Struts from WebWork. It is used in struts to access model objects from a jsp page. OGNL can be used to bing GUI elements to model objects in struts framework. It can be used to invoke methods of the model.
It can create lists,maps to be used with GUI,bind generic tags with model objects,convert one type to another.
Value Stack is an object created prior to any action method is executed and is used to store actions and other objects.
The struts framework stores the value stack in request attribute struts.valueStack and is used by jsp to display action and other info. Value Stack contains Object Stack and the Context Map.
Action and other objects are pushed ito the Object Stack where as maps(parameters,request,session,application,attr) are stored in Context Map To access Context Map properties we use a # in front of the OGNL expression, if not used search will take place from Object Stack.
eg #session.code returns the value of the session attribute code. Accessing Object Stack object properties [0].message, returns the message property valueof the object on top. [1]duration returns the duration property of the second object.
The automation of data transfer and type conversion is one of the most powerful features of Struts 2. With the help of OGNL, the Struts 2 framework allows transfer of data onto more complex Java-side types like List, Map, etc.
Custom converters can also be developed to extend the type conversion mechanism and it can handle any data type, including user-defined types.
OGNL is the interface between the Struts 2 framework string-based HTTP Input and Output and the Java-based internal processing. For developers who are conversant with OGNL, it will substantially improve efficiency and reduce maintenance headaches.
The framework sets the OGNL context to be our ActionContext, and the value stack to be the OGNL root object. (The value stack is a set of several objects, but to OGNL it appears to be a single object.) Along with the value stack, the framework places other objects in the ActionContext, including Maps representing the application, session, and request contexts. These objects coexist in the ActionContext, alongside the value stack (our OGNL root).