Rotating File code sample

Hi!
In the given example ...
public class FilegetRotatingFileName(File directory, String pattern, int cycle_length)throws IOException{
        public FilegetRotatingFileName(){
        int oldestFile = -1;
        long oldestTime = Long.MAX_VALUE;
        File f;   
        for(int i=0;i<cycle_length;i++){
        f = new File(directory,(i+1)+"_"+pattern);
        if(!f.exists()){
        f.createNewFile();
        return f;
        if(f.lastModified()><oldestTime){
        oldestTime = f.lastModified();
        oldestFile = i;
        f = new File(directory,(oldestFile+1)+"_"+pattern);
        return f;{
}    I cant get it compile ....
I want this code to span over 7 files in a directory named "Rotate"
I don't understand what is required for the "string pattern"
....and I'm not sure I've assembled the sample correctly
Thanks! (new to java)

I cant get it compile ....
public class FilegetRotatingFileName(File directory, String pattern, int cycle_length)throws IOException{
        public FilegetRotatingFileName(){Doesn't the class declaration look a bit strange to you? And the braces made no sense at all... By know I'd expect you to recognize a malformed method declaration if you see one.
How about
public File getRotatingFileName(File directory, String pattern, int cycle_length)throws IOException{
        int oldestFile = -1;
        long oldestTime = Long.MAX_VALUE;
        File f;   
        for(int i=0;i<cycle_length;i++){
        f = new File(directory,(i+1)+"_"+pattern);
        if(!f.exists()){
        f.createNewFile();
        return f;
        if(f.lastModified()><oldestTime){
        oldestTime = f.lastModified();
        oldestFile = i;
        f = new File(directory,(oldestFile+1)+"_"+pattern);
        return f;
f = new File(directory,(i+1)+"_"+pattern);Obviously it's looking for files named like 1_somename, with "somename" being the pattern.

Similar Messages

  • Java code sample for uploading file

    Guys can some one give me a java code sample for uploading more than 1 file .
    I have a working example but that is only for one file.
    thanks
    M

    Throw it away. Go to the [http://commons.apache.org/fileupload] and carefully read both 'User Guide' and 'Frequently Asked Questions' sections.
    And please, please also carefully read this article: [http://balusc.blogspot.com/2008/06/what-is-it-with-roseindia.html].

  • Is there a RH standard for formatting code samples?

    In the RH default style sheet, I do not see a pre HTML tag or other tag that will display code samples in a monospaced font.
    I created custom styles for a single line code sample and another style for multiline samples.
    We want our code samples to be shaded. If I shade multiple lines, each line being separated with a paragraph, there is a small amount of
    white space between each line. We do not like this either.
    I then created a custom table style with a single shaded cell. I add my multiline sample code, then I apply the custom paragraph style to get
    the font and spacing between lines that I want.
    Is there a different best practice for this, so that the code sample would be rendered correctly if viewed from other devices that read the HTML and
    may look for the pre HTML tag?
    I am using RoboHelp 9 and I provide the output as Eclipse help. Our help files are integrated into Eclipse help in the Eclipse IDE.
    Thank you.
    Cynthia

    Hi Cynthia
    As much as it pains me to say it, this is one case where using a Form element might be your best bet. I say this because often code samples are used or presented with the intent of copying and pasting into something like Windows Notepad. And if you used the TextArea form element, you can place the code there and make it pretty easy for folks to copy it for use elsewhere.
    I stand to be corrected on this because I am not a "power CSS" person. (meaning I am aware there are complete two and three day classes one might attend on all the nuances of CSS) But RoboHelp won't really do anything to help you a great deal in formatting things. But it might be possible, somehow, to configure CSS to accomplish your goal of making the code look as you want.
    Cheers... Rick

  • Laura, I need some code samples you mentioned...

    Laura,
    I posted a message a few days ago regarding calling Stored Procedures in my JDev 3.1 (JDK 1.2.2) BC4J application. I need to be able to call them two different ways. The first involves passing some parameters to the SP and recieving back the ResultSet. In the other instance I simply need to make a call to them to perform some tasks on the DB side. Nothing will be returned from these SP's. You discussed implementing the SQL as a VO and gave me some code showing me how I might do this. You also mentioned that it is possible to create a method on the AppMod and call this from the JSP client. I need to know which method should work best for me and to get the code samples for the second option.
    Thanks.
    Rob

    Hi,
    Here is the code I used for the custom method on my VO (same could be used from the app module rather than a specific VO). The stored procedure I am calling here performs some calculations and returns an integer value:
    public int getTotalHits(String mon, String year) {
    CallableStatement stmt = null;
    int total;
    String totalhits = "{? = call walkthru.total_hits(?,?)}";
    stmt = getDBTransaction().createCallableStatement(totalhits, 1);
    try
    // Bind the Statement Parameters and Execute this Statement
    stmt.registerOutParameter(1,Types.INTEGER);
    stmt.setString(2,mon);
    stmt.setString(3,year);
    stmt.execute();
    total = stmt.getInt(1);
    catch (Exception ex)
    throw new oracle.jbo.JboException(ex);
    finally
    try
    stmt.close();
    catch (Exception nex)
    return total;
    After adding the custom method to your appmoduleImpl.java file and rebuilt your BC4J project, do the following:
    1. Select the Application Module object and choose Edit from the context menu.
    2. Click on the Client Methods page. You should see the method you added in the Available list.
    3. Select the method and shuttle it to the Selected list.
    4. Click Finish. You should see a new file generated under the application module object node in the Navigator named appmodule.java that contains the client stubs for your method.
    5. Save and rebuild your BC4J project.
    I wrote a custom web bean to use from my JSP page to call the method on my VO:
    public class GetTotals extends oracle.jdeveloper.html.DataWebBeanImpl {
    public void render() {
    int totalhits;
    try
    Row[] rows;
    // Retrieve all records by default, the qView variable is defined in the base class
    qView.setRangeSize(-1);
    qView.first();
    rows = qView.getAllRowsInRange();
    // instantiate a view object for our exported method
    // and call the stored procedure to get the total
    ViewObject vo = qView.getViewObject();
    wtQueryView theView = (wtQueryView) vo;
    totalhits = theView.getTotalHits(session.getValue("m").toString(),session.getValue("y").toString());
    out.println(totalhits);
    } catch(Exception ex)
    throw new RuntimeException(ex.getMessage());
    I just call the render method on this custom web bean from the JSP. I am not passing parameters to the render method of the bean, but instead access the parameters I need from the session:
    session.getValue("m").toString()
    I set these session parameters from the JSP that is called when the user submits their query criteria form. For example:
    // get the view parameter from the form String month = request.getParameter("month");
    String year = request.getParameter("year");
    // store the information for reference later session.putValue("m", month); session.putValue("y", year);
    Hope this helps.

  • InterMedia Code Samples Error

    Hi,
    I'm trying to install "Oracle8i interMedia Text 8.1.x Code Samples" and I'm experiencing problems when I run the spider.
    The spider.pl files contains the following lines:
    # open the parameter file 'params'
    open(PARAMS, "params") &#0124; &#0124; print STDERR "cannot open the parameter file\n";
    while(<PARAMS>)...
    The issue is that it cannot find the "params" file. Neither can I in the archive I downloaded from technet.
    Thanks for help
    Dan
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by just searching:
    Hi
    Created a table called Content
    with columns
    id Number(100,
    description varchar2(2000),
    Doc doctype
    where doctype is
    document BLOB,mimetype varchar2(100),
    Doc is used to load only HTML content
    Found that text index does not get created properly on doctype.document column.
    Also if we create a text index on description
    , then if we have to delete some rows from content we get this wrror
    ERROR at line 1:
    ORA-29876: failed in the execution of the ODCIINDEXDELETE routine
    ORA-20000: ConText error:
    DRG-10602: failed to queue DML change to column DESCRIPTION for primary key AAADFLAAFAAAAD9AAB
    DRG-50857: oracle error in drekqkd(execute k_stmt)
    ORA-00942: table or view does not exist
    any solutions
    thank you
    just searching
    <HR></BLOCKQUOTE>
    try to create primary key constraint
    alter table tablename
    add ( primary key id number )
    null

  • Code Sample: cardinfo for JCOP41V22 Card

    Listed below is the code sample, cardinfo.java, deduced from loader.java for JCOP41V22 card:
    import java.io.*;
    import com.ibm.jc.*;
    import com.ibm.jc.terminal.*;
    * Sample cardinfo. Demonstrates how to use the offcard API to list applets informatoin,
    * JCOP41V22 by shrinking the loader.java code.
    * Modified by: freiheit / 13/10/2005
    public class cardinfo{
         protected static final byte[] JCOP_CARD_MANAGER_AID = { (byte) 0xa0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00};
         protected static final byte defaultInstallParam[] = { -55, 0 }; // don't know what it's for
         public static void main(String[] args){
         if (args.length == 0){
         System.out.println("cardinfo.main(): missing cap-file argument");
         System.exit(1);
         try{
         cardinfo l = new cardinfo();
         //l.load(args[0]);
         l.getcardinfo();
         }catch(Exception e){
         System.err.println("EX: msg " + e.getMessage() + ", class " + e.getClass());
         e.printStackTrace(System.err);
         System.exit(0);
    private cardinfo(){}
    //private void load(String capFileName) throws Exception{
    private void getcardinfo() throws Exception{
         //CapFile capFile = new CapFile(capFileName, null);
    /*CapFile capFile = new CapFile("C:\\Documents and Settings\\Seah Peng Chew\\workspace\\Helloworld\\bin\\com\\acme\\helloworld\\javacard\\helloworld.cap", null);
         System.out.println("Package name: " + capFile.pkg);
         byte[][] applets = capFile.aids;
         if ((applets == null) || (applets.length == 0)){
         throw new RuntimeException("no applets in cap file");
         // Get connection to terminal, we look for the simulation.
         // As you might want to use "pcsc", "4" or "tcl", "10" in case of
         // Windows or "PCSC", null in case of Linux, you should pass the name
         // of the terminal on the command line or in a properties file
         System.out.println("Open terminal ...");     
         //Make sure the simulator jcop.exe is activated before unmark this satement
         //before running
         //Issue /close command at "cm" prompt if the card is in use,, ie it should
         //have "-" prompt.
         JCTerminal term = JCTerminal.getInstance("Remote", null);
         //For real JCOP41V22 card, please unmark this statement before running
         //Issue /close command at "cm" prompt if the card is in use,, ie it should
         //have "-" prompt.
         //JCTerminal term = JCTerminal.getInstance("pcsc:4", null);
         term.open();
         term.waitForCard(5000);
         TraceJCTerminal _term = new TraceJCTerminal();
         _term.setLog(new PrintWriter(System.out));
         _term.init(term);
         term = _term;
         System.out.println("Get card ...");
         JCard card = new JCard(term, null, 2000);
         System.out.println("Select card manager ...");
         CardManager cardManager = new CardManager(card, CardManager.daid);     
         cardManager.select();
         byte[] dfltKey = c2b("404142434445464748494a4b4c4d4e4f");
         cardManager.setKey(new OPKey(255, 1, OPKey.DES_ECB, dfltKey));
         cardManager.setKey(new OPKey(255, 2, OPKey.DES_ECB, dfltKey));
         cardManager.setKey(new OPKey(255, 3, OPKey.DES_ECB, dfltKey));
         System.out.println("Authenticate to card manager ...");
         cardManager.initializeUpdate(255, 0, CardManager.SCP_UNDEFINED);
         cardManager.externalAuthenticate(OPApplet.APDU_CLR);
         cardManager.update();
         JCInfo info = JCInfo.INFO;
         System.out.println("\nCardManager AID : " + JCInfo.dataToString(cardManager.getAID()));
         System.out.println("CardManager state : " + info.toString("card.status", (byte) cardManager.getState()) + "\n");
         Object[] app = cardManager.getApplets(1, 0, true);
         if (app == null) {
         System.out.println("No applets installed on-card");
         } else {
         System.out.println("Applets:");
         for (int i = 0; i < app.length; i++) {
              System.out.println(info.toString("applet.status", (byte) ((OPApplet) app).getState()) + " " + JCInfo.dataToString(((OPApplet) app[i]).getAID()));
         Object[] lf = cardManager.getLoadFiles(0, true);
         if (lf == null) {
         System.out.println("No packages installed on-card");
         } else {
         System.out.println("Packages:");
         for (int i = 0; i < lf.length; i++) {
              System.out.println(info.toString("loadfile.status", (byte)((LoadFile) lf[i]).getState()) + " " + JCInfo.dataToString(((LoadFile) lf[i]).getAID()));
         term.close();
    static String numbers = "0123456789abcdef";
    private byte[] c2b(String s) {
         if (s == null) return null;
         if (s.length() % 2 != 0) throw new RuntimeException("invalid length");
         byte[] result = new byte[s.length() / 2];
         for (int i = 0; i < s.length(); i += 2) {
         int i1 = numbers.indexOf(s.charAt(i));
         if (i1 == -1) throw new RuntimeException("invalid number");
         int i2 = numbers.indexOf(s.charAt(i + 1));
         if (i2 == -1) throw new RuntimeException("invalid number");
         result[i / 2] = (byte) ((i1 << 4) | i2);
         return result;
    I have tested the code with JCOP Plug-in 3.1.1a in Windows environment.
    Please give your comments and feedback.

    The posted code had some errors in the part which enumerate the installed applets and packages. I corrected that.
    Second I changed the class name from "cardinfo" to "CardInfo", because of java code style.
    import java.io.PrintWriter;
    import com.ibm.jc.CardManager;
    import com.ibm.jc.JCInfo;
    import com.ibm.jc.JCTerminal;
    import com.ibm.jc.JCard;
    import com.ibm.jc.LoadFile;
    import com.ibm.jc.OPApplet;
    import com.ibm.jc.OPKey;
    import com.ibm.jc.terminal.TraceJCTerminal;
    * Sample cardinfo. Demonstrates how to use the offcard API to list applets informatoin, JCOP41V22
    * by shrinking the loader.java code. Modified by: freiheit / 13/10/2005
    public class CardInfo {
        protected static final byte[] JCOP_CARD_MANAGER_AID = { (byte) 0xa0, 0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00 };
        protected static final byte defaultInstallParam[] = { -55, 0 }; // don't know what it's for
        public static void main(String[] args) {
             * if (args.length == 0){ System.out.println("cardinfo.main(): missing cap-file argument");
             * System.exit(1); }
            try {
                CardInfo l = new CardInfo();
                // l.load(args[0]);
                l.getcardinfo();
            } catch (Exception e) {
                System.err.println("EX: msg " + e.getMessage() + ", class " + e.getClass());
                e.printStackTrace(System.err);
            System.exit(0);
        private CardInfo() {
        // private void load(String capFileName) throws Exception{
        private void getcardinfo() throws Exception {
            // CapFile capFile = new CapFile(capFileName, null);
             * CapFile capFile = new CapFile("C:\\Documents and Settings\\Seah Peng
             * Chew\\workspace\\Helloworld\\bin\\com\\acme\\helloworld\\javacard\\helloworld.cap",
             * null); System.out.println("Package name: " + capFile.pkg); byte[][] applets =
             * capFile.aids; if ((applets == null) || (applets.length == 0)){ throw new
             * RuntimeException("no applets in cap file"); }
            // Get connection to terminal, we look for the simulation.
            // As you might want to use "pcsc", "4" or "tcl", "10" in case of
            // Windows or "PCSC", null in case of Linux, you should pass the name
            // of the terminal on the command line or in a properties file
            System.out.println("Open terminal ...");
            // Make sure the simulator jcop.exe is activated before unmark this satement
            // before running
            // Issue /close command at "cm" prompt if the card is in use,, ie it should
            // have "-" prompt.
            JCTerminal term = JCTerminal.getInstance("Remote", null);
            // For real JCOP41V22 card, please unmark this statement before running
            // Issue /close command at "cm" prompt if the card is in use,, ie it should
            // have "-" prompt.
            // JCTerminal term = JCTerminal.getInstance("pcsc:4", null);
            term.open();
            term.waitForCard(5000);
            TraceJCTerminal _term = new TraceJCTerminal();
            _term.setLog(new PrintWriter(System.out));
            _term.init(term);
            term = _term;
            System.out.println("Get card ...");
            JCard card = new JCard(term, null, 2000);
            System.out.println("Select card manager ...");
            CardManager cardManager = new CardManager(card, CardManager.daid);
            cardManager.select();
            byte[] dfltKey = c2b("404142434445464748494a4b4c4d4e4f");
            cardManager.setKey(new OPKey(255, 1, OPKey.DES_ECB, dfltKey));
            cardManager.setKey(new OPKey(255, 2, OPKey.DES_ECB, dfltKey));
            cardManager.setKey(new OPKey(255, 3, OPKey.DES_ECB, dfltKey));
            System.out.println("Authenticate to card manager ...");
            cardManager.initializeUpdate(255, 0, CardManager.SCP_UNDEFINED);
            cardManager.externalAuthenticate(OPApplet.APDU_CLR);
            cardManager.update();
            JCInfo info = JCInfo.INFO;
            System.out.println("\nCardManager AID : " + JCInfo.dataToString(cardManager.getAID()));
            System.out.println("CardManager state : "
                    + info.toString("card.status", (byte) cardManager.getState()) + "\n");
            OPApplet[] app = (OPApplet[]) cardManager.getApplets(1, 0, true);
            if (app == null) {
                System.out.println("No applets installed on-card");
            } else {
                System.out.println("Applets:");
                for (int i = 0; i < app.length; i++) {
                    System.out.println(info.toString("applet.status", (byte) app.getState()) + " "
    + JCInfo.dataToString(app[i].getAID()));
    LoadFile[] lf = cardManager.getLoadFiles(0, true);
    if (lf == null) {
    System.out.println("No packages installed on-card");
    } else {
    System.out.println("Packages:");
    for (int i = 0; i < lf.length; i++) {
    System.out.println(info.toString("loadfile.status", (byte) lf[i].getState()) + " "
    + JCInfo.dataToString(lf[i].getAID()));
    term.close();
    static String numbers = "0123456789abcdef";
    private byte[] c2b(String s) {
    if (s == null)
    return null;
    if (s.length() % 2 != 0)
    throw new RuntimeException("invalid length");
    byte[] result = new byte[s.length() / 2];
    for (int i = 0; i < s.length(); i += 2) {
    int i1 = numbers.indexOf(s.charAt(i));
    if (i1 == -1)
    throw new RuntimeException("invalid number");
    int i2 = numbers.indexOf(s.charAt(i + 1));
    if (i2 == -1)
    throw new RuntimeException("invalid number");
    result[i / 2] = (byte) ((i1 << 4) | i2);
    return result;

  • ITunes U Code Samples Update! (Aug 3.)

    In case you missed it (I know I did), there are new code samples available on the iTunesU Support Site:
    http://images.apple.com/support/itunesu/docs/iTunes_UCodeSamples.zip
    The familiar Java and Perl examples can be found there, but there are also options for C, Python and shell.
    It also seems that the Perl example has changed -- code that I have in my version is no longer in the new one. Any chance we can get a diff file from Apple with the changes?
    And finally, for those who missed it, user-contributed C# and PHP authentication schemes have been posted to the forums:
    C# by Ed at NAIT
    http://discussions.apple.com/thread.jspa?threadID=557503&tstart=15
    PHP by Aaron Axelsen
    http://discussions.apple.com/thread.jspa?threadID=520959&tstart=45

    Hi,
    The release notes should contain information on when the example scripts change. They won't contain diffs, basically just an FYI.
    Duncan

  • EP Code samples source location

    Hi,
    I am new a new member in the EP fraternity. I found a lot of examples in the portal services PDF document I downloaded from sdn. But I am unable to find the source of the examples mentioned in the document. Like for example, JCoClientPool.java etc..And also I am unable to locate the PDV files like portaldataviewer.zar, PortalDataViewer.par and PortalDVSamples.par.
    Helping me finding these files is greatly appreciated.
    Thanks,
    -Chakri

    Hi Chakri B,
    Welcome to SDN. If u r looking for some code samples u can get it from PDK. Its a seperate installtion. U can download the setup for PDK from SDN itself. Try this link for PDK
    https://www.sdn.sap.com/sdn/downloaditem.sdn?res=/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/6faddbaa-0501-0010-d5b3-83ec16f6b8fc
    Download it and add PDK to the portal.
    It has details abt the various portal developments.
    Also u can find documentaion about Portal componets from www.help.sap.com.
    If ur looking for some code then u can also find that from SDN code samples. Search in code samples.
    Many of the par files are provided with portal itself. You can download the same from ur server as mentioned in the pervious reply.
    Hope this Helps
    gEorgE

  • Any code samples using StringWriter?

    I looked through the examples here and couldn't find one that used StringWriter. Does anyone know where a code sample using it can be found?
    Thanks

    OK... I got a small sample program to work but I am having trouble getting this one to work with StringWriter. I get an error on the line containing ---- s = new String(sw.toString); It says it can't resolve symbol. Here is the part of the code that is giving me trouble.
    try {
                   fin = new FileInputStream(args[0]);
              } catch (FileNotFoundException e) {
                   System.out.println("File not Found");
                   return;
              } catch (ArrayIndexOutOfBoundsException e) {
                   System.out.println("Usage: ShowFile File");
                   return;
              do {
                   i = fin.read();
                   if (i != -1) {
                        pw.print(i);                         
              } while(i != -1);
              fin.close();
              s = new String(sw.toString);
              StringTokenizer st = new StringTokenizer(s);     (I didn't put the import statements, variable declarations or main line for clarity). I also tried putting sw as the argument for StringTokenizer() as well and it didn' work.
    Any help would be great.
    Thanks

  • JMF code samples?

    Hi,
    I am have just installed JMF and have it working and up and running. I haven't used JMF before and want to learn how program using it! What i want to do is to take a picture from my webcam and save it.
    Are there any library's of code samples or tutorials that anyone can think of that could help me out? Or even books I can read?
    Many Thanks

    I have written a small app that can maybe get you started, its a little rough around the edges but it works :-)
    Code below (BasicWebCam.java):
    If you want the Eclispe project, let me know and I will send it to you.
    import java.awt.Component;
    import java.awt.EventQueue;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import java.io.FileOutputStream;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import javax.media.Buffer;
    import javax.media.CaptureDeviceInfo;
    import javax.media.CaptureDeviceManager;
    import javax.media.Manager;
    import javax.media.MediaLocator;
    import javax.media.Player;
    import javax.media.control.FrameGrabbingControl;
    import javax.media.format.VideoFormat;
    import javax.media.util.BufferToImage;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.JButton;
    import com.sun.image.codec.jpeg.JPEGCodec;
    import com.sun.image.codec.jpeg.JPEGEncodeParam;
    import com.sun.image.codec.jpeg.JPEGImageEncoder;
    public class BasicWebCam extends JFrame implements ActionListener {
    private JPanel contentPane;
    private JPanel pnlCam = new JPanel();
    public CaptureDeviceInfo captureDeviceInfo;
    public MediaLocator mediaLocator;
    public Player player;
    private Component comp;
    public javax.swing.Timer timer = new javax.swing.Timer(250, (ActionListener) this);
    public Buffer BUF;
    public Image img;
    public BufferToImage BtoI;
    * Launch the application.
    public static void main(String[] args) {
         EventQueue.invokeLater(new Runnable() {
         public void run() {
              try {
              BasicWebCam frame = new BasicWebCam();
              frame.setVisible(true);
              } catch (Exception e) {
              e.printStackTrace();
    * Create the frame.
    public BasicWebCam() {
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setBounds(100, 100, 353, 327);
         contentPane = new JPanel();
         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
         setContentPane(contentPane);
         contentPane.setLayout(null);
         pnlCam.setBounds(10, 11, 320, 240);
         contentPane.add(pnlCam);
         JButton btnCapture = new JButton("Capture");
         btnCapture.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
              actionCapture();
         btnCapture.setBounds(124, 262, 89, 23);
         contentPane.add(btnCapture);
         init();
    public void init() {
         String strDevice = "vfw:Microsoft WDM Image Capture (Win32):0";
         mediaLocator = new MediaLocator("vfw://0");
         // FOR LINUX
         // String strDevice = "v4l:Laptop Integrated Webcam:0";
         // mediaLocator = new MediaLocator("v4l://0");
         captureDeviceInfo = CaptureDeviceManager.getDevice(strDevice);
         showVid();
    private void showVid() {
         try {
         player = Manager.createRealizedPlayer(mediaLocator);
         player.start();
         if ((comp = player.getVisualComponent()) != null) {
              comp.setSize(pnlCam.getWidth(), pnlCam.getHeight());
              // comp.setPreferredSize(new Dimension(pnlCapture.getWidth(),
              // pnlCapture.getHeight()));
              pnlCam.add(comp);
         Thread.sleep(5000);
         timer.start(); // start timer
         } catch (Exception e) {
         e.printStackTrace();
    public void actionCapture() {
         // Grab a frame
         // comp.setSize(pnlCapture.getWidth(), pnlCapture.getHeight());
         FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
         BUF = fgc.grabFrame();
         // Convert it to an image
         BtoI = new BufferToImage((VideoFormat) BUF.getFormat());
         img = BtoI.createImage(BUF);
         // resize
         img = resizeImage(img, pnlCam.getWidth(), pnlCam.getHeight());
         // show the image
         // pnlImage.setImage(img);
         img.getGraphics().drawString(getDateTime("yyyy/MM/dd HH:mm:ss") + " - ColinCoderator", 50, 235);
         // save image
         String fileName = getDateTime("yyyy-MM-dd_HH-mm-ss") + ".jpg";
         String path = "c:/projects/BasicWebCam/" + fileName;
         System.out.println(path);
         // save image
         saveJPG(img, path);
    public static void saveJPG(Image img, String s) {
         BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
         Graphics2D g2 = bi.createGraphics();
         g2.drawImage(img, null, null);
         FileOutputStream out = null;
         try {
         out = new FileOutputStream(s);
         } catch (java.io.FileNotFoundException io) {
         System.out.println("File Not Found");
         JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
         JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
         param.setQuality(0.5f, false);
         encoder.setJPEGEncodeParam(param);
         try {
         encoder.encode(bi);
         out.close();
         } catch (java.io.IOException io) {
         System.out.println("IOException");
    public Image resizeImage(Image img, int width, int height) {
         BufferedImage resizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
         Graphics2D g = resizedImage.createGraphics();
         g.drawImage(img, 0, 0, width, height, null);
         g.dispose();
         return resizedImage;
    public static String getDateTime(String format) {
         DateFormat dateFormat = new SimpleDateFormat(format);
         Calendar cal = Calendar.getInstance();
         return (dateFormat.format(cal.getTime()));
    @Override
    public void actionPerformed(ActionEvent arg0) {
         // TODO Auto-generated method stub
    }

  • 2004 Code samples

    Hi
    I have written a few pieces of code for sbo 6.5 and now need to write some code for 2004. I know the code is similar, are there any code samples for 2004 ? I can only see 6.5 samples
    Many thanks
    Andy

    Hi Andy,
    When you install the SDK Implementation on the SAP Business One CD then you have access only to the help files and samples of the UI API.
    To have access to the DI samples and help files you need another CD exclusive for the SDK. If you use the setup.exe inside the SDK CD and you click on Custom you can see the possibility of installing DI and UI help files and samples.
    If it doesn't work please deinstall the SDK implementation and then install the SDK on the SDK CD.
    Hope it helps
    Trinidad.

  • Tutorial or code sample in creating a .exe for windows

    Hi all,
    Can some kind soul guide me to a tutorial / materials / code sample in creating a .exe (for a java program) to run in windows ?
    My intention is to create a .exe such that when it is clicked, the java program runs.
    thanks a bundle.

    Java in not intended to compile into system executables. IMO, you should not do this, let your application remain cross-platform. You can simply make an executable JAR file, which makes your application run with a double-click on any system which have a JRE installed.
    Anyway, if you really want to help M$ solidify their work, search the forum. It has been asked and answered several times. You have two options:
    1. Bundle a version of JRE with your application, and create an executable file which runs your application on the bundled JRE.
    2. Use a native code compiler like ( http://www.excelsior-usa.com/jet.html ).
    Also, try these:
    http://www.dobysoft.com/products/nativej/
    http://www.ej-technologies.com/products/exe4j/overview.html

  • Code sample to dequeue messages

    I am looking for a code sample to dequeue messages from CRM OD? How do I retrieve the xml file after it is generated. Do I need to use a web service to retrieve that?
    Preference would be to get the code snippet in java, but not necessary.
    Thanks.

    Hi,
    I'm assuming you are referring to integration event messages? If so, then yes, you do need to use WS in order to retrieve them from CRMOD. Please refer to the CRM On Demand online help for Integration Events. It will provide details on downloading the WSDL file for Integration Events and the schema files which are required to process the events once they are retrieved. The WS User Guide contains details regarding the use of the GetEvents and DeleteEvents methods to retrieve and delete events from the queue.
    Sorry, I don't currently have a code sample that I can provide.
    Thanks,
    Sean

  • Rotate File with Date Stamp and Zip

    Hey Guys
    New to powershell.. Just want to write a simple script to do the following. The file is called D:\test.log
    1) Rotate it every night at 12pm (I guess schedule via task manager)
    2) Rename it to YYYY-MM-DD-filename.log at that time. Create a new file called test.log so current logging can continue (or just keeps running on that file after rename of file)
    3) Zip it. and leave it there..
    Can anyone help on how to do so? And also if I want to expand this script to do multiple files (but same rotated file format), that would be helpful (I guess some for each statement ? )
    Will run on Windows 2008 R2 Servers..
    Appreciate your help!!!

    Here is a good place to start:http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx
    Look at how to manage dates and how to manage files.
    When you have a start and get stuck post back with a specific question.
    You can learn to write a script in PowerShell in less than a weekend if you start with the introductory videos.
    ¯\_(ツ)_/¯

  • Java Proxy Code Sample

    Hello SAP community. Does anyone have a step-by-step code sample for creating either a jsp or web dynpro application in Netweaver to use a java proxy to connect to XI that will calls a RFC or BAPI in SAP R3?

    Hi
    See the Code sample and pdf help it the SDN samples and tutorials
    https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/f0b0e990-0201-0010-cc96-d7ecd2e51715
    https://www.sdn.sap.com/irj/sdn/developerareas/webdynpro?rid=/library/uuid/49f2ea90-0201-0010-ce8e-de18b94aee2d
    Kind Regards
    Mukesh

Maybe you are looking for

  • How do I permanently delete file(s) in CS5 in Windows 7?

    In Windows this is Shift-Delete. I can only get 'Send .... to the Recycle Bin' in Bridge CS5.

  • BPM collect pattern based on payload

    Hi, i am doing BPM Collect pattern based on stop message which is RFC. Means, i need to collect the IDOCs until i get the RFC from another system. For this i am using predefined pattern BPMcolllect pattern which is in BASIS SWCV. is it possible to do

  • Read a file

    i wrot the follwing code to search for a word in a list of files when i compile it ,it does not give me any error , but at run it give me the following Eception: java.io.FileNotFoundException: home.html (The system cannot find the file specified)    

  • I bought iWork family. Do I need to buy a app for iCloud too?

    I bought iWork family. Do I need to buy a app for iCloud too?

  • Gps not working properly after 3.0 update

    I have an unlcoked iPhone with version 3.0. Before I installed the update to the new version my gps worked great. It was very accurate and would follow along when traveling. Ever since I applied the update the gps is way off by 20-30 miles and it wil