Here is the source code to JMF Webcam app + saves jpeg

Since so many people ask for this code, but never get it, I figured I'd repost it. I didn't write it, but I added the jpeg saving part, and modified it for my device, which you will have to do to get it to work. Just go into JMFRegistry and get the device name from your webcam and then edit the code. Also, keep in mind that some webcams don't work with JMF. You have to have a webcam that supports VFW or WDM interface.
And here's the code:
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import javax.media.*;
import javax.media.format.*;
import javax.media.util.*;
import javax.media.control.*;
import javax.media.protocol.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import com.sun.image.codec.jpeg.*;
public class SwingCapture extends Panel implements ActionListener
  public static Player player = null;
  public CaptureDeviceInfo di = null;
  public MediaLocator ml = null;
  public JButton capture = null;
  public Buffer buf = null;
  public Image img = null;
  public VideoFormat vf = null;
  public BufferToImage btoi = null;
  public ImagePanel imgpanel = null;
  public SwingCapture()
    setLayout(new BorderLayout());
    setSize(320,550);
    imgpanel = new ImagePanel();
    capture = new JButton("Capture");
    capture.addActionListener(this);
    String str1 = "vfw:Logitech USB Video Camera:0";
    String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
    di = CaptureDeviceManager.getDevice(str2);
    ml = di.getLocator();
    try
      player = Manager.createRealizedPlayer(ml);
      player.start();
      Component comp;
      if ((comp = player.getVisualComponent()) != null)
        add(comp,BorderLayout.NORTH);
      add(capture,BorderLayout.CENTER);
      add(imgpanel,BorderLayout.SOUTH);
    catch (Exception e)
      e.printStackTrace();
  public static void main(String[] args)
    Frame f = new Frame("SwingCapture");
    SwingCapture cf = new SwingCapture();
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
      playerclose();
      System.exit(0);}});
    f.add("Center",cf);
    f.pack();
    f.setSize(new Dimension(320,550));
    f.setVisible(true);
  public static void playerclose()
    player.close();
    player.deallocate();
  public void actionPerformed(ActionEvent e)
    JComponent c = (JComponent) e.getSource();
    if (c == capture)
      // Grab a frame
      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);
      // show the image
      imgpanel.setImage(img);
      // save image
      saveJPG(img,"c:\\test.jpg");
  class ImagePanel extends Panel
    public Image myimg = null;
    public ImagePanel()
      setLayout(null);
      setSize(320,240);
    public void setImage(Image img)
      this.myimg = img;
      repaint();
    public void paint(Graphics g)
      if (myimg != null)
        g.drawImage(myimg, 0, 0, this);
  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");

Hi William,
I've tried this code but I always get an null fgc with the following line.
FrameGrabbingControl fgc = (FrameGrabbingControl)player.getControl("javax.media.control.FrameGrabbingCotrol");
So the player returns always null. The other thigns seem to be fine. I can view the image in the application but when I click capture it throws a Null Pointer Exception because fgc is null.
I am using Logitech QuickCam, USB, Win2k, jdk 1.3.1, JMF 2.1.1
Can you help me?
thanx,
Philip
Since so many people ask for this code, but never get
it, I figured I'd repost it. I didn't write it, but I
added the jpeg saving part, and modified it for my
device, which you will have to do to get it to work.
Just go into JMFRegistry and get the device name from
your webcam and then edit the code. Also, keep in mind
that some webcams don't work with JMF. You have to
have a webcam that supports VFW or WDM interface.
And here's the code:
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import javax.media.*;
import javax.media.format.*;
import javax.media.util.*;
import javax.media.control.*;
import javax.media.protocol.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import com.sun.image.codec.jpeg.*;
public class SwingCapture extends Panel implements
ActionListener
public static Player player = null;
public CaptureDeviceInfo di = null;
public MediaLocator ml = null;
public JButton capture = null;
public Buffer buf = null;
public Image img = null;
public VideoFormat vf = null;
public BufferToImage btoi = null;
public ImagePanel imgpanel = null;
public SwingCapture()
setLayout(new BorderLayout());
setSize(320,550);
imgpanel = new ImagePanel();
capture = new JButton("Capture");
capture.addActionListener(this);
String str1 = "vfw:Logitech USB Video Camera:0";
String str2 = "vfw:Microsoft WDM Image Capture
ure (Win32):0";
di = CaptureDeviceManager.getDevice(str2);
ml = di.getLocator();
try
player = Manager.createRealizedPlayer(ml);
player.start();
Component comp;
if ((comp = player.getVisualComponent()) !=
)) != null)
add(comp,BorderLayout.NORTH);
add(capture,BorderLayout.CENTER);
add(imgpanel,BorderLayout.SOUTH);
catch (Exception e)
e.printStackTrace();
public static void main(String[] args)
Frame f = new Frame("SwingCapture");
SwingCapture cf = new SwingCapture();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
playerclose();
System.exit(0);}});
f.add("Center",cf);
f.pack();
f.setSize(new Dimension(320,550));
f.setVisible(true);
public static void playerclose()
player.close();
player.deallocate();
public void actionPerformed(ActionEvent e)
JComponent c = (JComponent) e.getSource();
if (c == capture)
// Grab a frame
FrameGrabbingControl fgc =
fgc = (FrameGrabbingControl)
player.getControl("javax.media.control.FrameGrabbingCo
trol");
buf = fgc.grabFrame();
// Convert it to an image
btoi = new
= new BufferToImage((VideoFormat)buf.getFormat());
img = btoi.createImage(buf);
// show the image
imgpanel.setImage(img);
// save image
saveJPG(img,"c:\\test.jpg");
class ImagePanel extends Panel
public Image myimg = null;
public ImagePanel()
setLayout(null);
setSize(320,240);
public void setImage(Image img)
this.myimg = img;
repaint();
public void paint(Graphics g)
if (myimg != null)
g.drawImage(myimg, 0, 0, this);
public static void saveJPG(Image img, String s)
BufferedImage bi = new
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 =
r = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param =
m = 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");

Similar Messages

  • Is there a way to hide the source code in an Xcode app?

    Whenever I export an Applescript app from Xcode, in the resources folder, there is the unprotected source code. Someone else has changed the source code a bit and has begun distributing my app as his own. Is there anyway to compile or encrypt this code on export?

    In your project's build settings there is an OSACompile - Build Options section where you can select the option to Save as Execute-Only.  The run-only script isn't encrypted, but I haven't heard of anyone taking the time to decompile one.  Note that even though the script is no longer easily readable, text strings and variable/method names can still be seen.

  • View Source Code of Existing iPhone Apps

    Is there a way to view the source code of existing iPhone Apps?

    The files uploaded to the iTunes store are only those included in the .app package. These include all the resources, so all the .nib files would be there, but there's no source code in that package as far as I know. You can view the package you would upload by expanding the Product folder in the Xcode Groups & Files tree. Then Ctrl-click on the .app icon, select Reveal in Finder, Ctrl-click on the .app package and select Show Package Contents.
    Lots of independent developers (as distinct from corporation employees) are willing to share their knowledge including excerpts from their code, and that's what this forum is all about. I've pasted lots of source code from my app into the answers I've provided in this forum. If you contact a developer privately, I think it would be better to ask "How did you do that?" instead of asking for the complete source code. But there are lots of people out there who enjoy teaching others even more than protecting their ideas. My only disappointment in this forum is that many (but certainly not all!!) are really good at saying "please", but seem to have some language problem with "thank you".

  • How to display the source code for this friggin' file.

    Below is a rather lengthy bit of code that provides the behavior and attributes of a web server for OpenCyc. I need to know if I can enter some java to have the HTML source code displayed in a separate text file whenever this class returns some resulting webpage. If you have any ideas it will be greatly appreciated.
    -"Will code for foo."
    package org.opencyc.webserver;
    * Class WebServer is simple multithreaded HTTP server
    * with CGI limited to a Cyc connection on default port 3600.
    * <p>
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import java.util.jar.*;
    import java.text.*;
    import org.opencyc.util.*;
    public class WebServer extends Thread {
         * Singleton WebServer instance.
        public static WebServer current;
         * Default HTTP port.
        protected static int DEFAULT_PORT = 80;
         * Default Cyc base port.
        protected static int DEFAULT_CYC_PORT = 3600;
         * Default directory to serve files from on non-Windows OS.
        protected static String DEFAULT_DIR = "/";
         * Default directory to serve files from on Windows.
        //protected static String DEFAULT_WIN_DIR = "C:\\";
        protected static String DEFAULT_WIN_DIR = "k:\\opencyc\\run\\httpd\\htdocs";
         * File cache capacity.
        protected static final int CACHE_CAPACITY = 100;
         * File cache to improve file serving performance.
        protected static Hashtable fileCache = new Hashtable(CACHE_CAPACITY);
         * Number of files served from this web server.
        protected static long nbrFilesServed = 0;
         * Number of files served from this web server that were found in the cache.
        protected static long nbrCacheHits = 0;
         * Server socket for accepting connections.
        protected ServerSocket server;
         * Directories to serve files from.
        protected ArrayList dirs;
         * Map from String (jar root) to JarFile[] (jar class path).
        protected HashMap map;
         * Webserver HTTP port.
        protected int port;
         * Cyc HTML host.
        protected String cycHost = "localhost";
         * Cyc HTML port.
        protected int cycPort;
         * Expand jar tress.
        protected boolean trees;
         * Requests flag.
        protected boolean traceRequests;
         * Constructs a WebServer object.
         * @param port the port to use
         * @param directories the directory to serve files from
         * @param trees true if files within jar files should be served up
         * @param traceRequests true if client's request text should be logged.
         * @exception IOException if the listening socket cannot be opened, or problem opening jar files.
        public WebServer() throws IOException {
            getProperties();
            server = new ServerSocket(port);
            processDirectories();
         * Class Task processes a single HTTP request.
        protected class Task extends Thread {
             * Socket for the incoming request.
            protected Socket sock;
             * Client socket to the Cyc KB HTML server.
            protected Socket cycHtmlSocket;
             * Output tcp stream.
            protected DataOutputStream out;
             * Contains the file request path for a not-found error message.
            protected String notFoundPath;
             * Contains the first line of a request message.
            protected String methodLine;
             * Contains the body of a POST method.
            protected String bodyLine;
             * Constructs a Task object.
             * @param sock the socket assigned for this request.
            public Task(Socket sock) {
                this.sock = sock;
             * Processes the HTTP request.
            public void run() {
                if (traceRequests)
                    Log.current.println("connection accepted from " + sock.getInetAddress());
                notFoundPath = "";
                try {
                    out = new DataOutputStream(sock.getOutputStream());
                    try {
                        getBytes();
                    catch (Exception e) {
                        Log.current.println("file not found: " + notFoundPath);
                        try {
                            out.writeBytes("HTTP/1.1 404 Not Found\r\n");
                            out.writeBytes("Server: Cyc WebServer\r\n");
                            out.writeBytes("Connection: close\r\n");
                            out.writeBytes("Content-Type: text/html\r\n\r\n");
                            out.writeBytes("<HTML><HEAD>\n");
                            out.writeBytes("<TITLE>404 Not Found</TITLE>\n");
                            out.writeBytes("</HEAD><BODY>\n");
                            out.writeBytes("<H1>404 - Not Found</H1>\n");
                            out.writeBytes("</BODY></HTML>");
                            out.flush();
                        catch (SocketException se) {
                catch (Exception e) {
                    Log.current.printStackTrace(e);
                finally {
                    try {
                        sock.close();
                    catch (IOException e) {
             * Reads the HTTP request and obtains the response.
             * @exception IOException when HTTP request has an invalid format.
            private void getBytes() throws IOException {
                // Below logic is complex because web browsers do not close the
                // socket after sending the request, so must parse message to find
                // the end.
                BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
                ArrayList inBytes = new ArrayList(200);
                int ch = 0;
                boolean postMethod;
                methodLine = in.readLine();
                //if (traceRequests)
                //    Log.current.println("methodLine=" + methodLine);
                bodyLine = "";
                if (methodLine.startsWith("POST /"))
                    postMethod = true;
                else
                    postMethod = false;
                //if (traceRequests)
                //    Log.current.println("postMethod=" + postMethod);
                int ch1 = -1;
                int ch2 = -1;
                int ch3 = -1;
                int ch4 = -1;
                // Read the HTTP request headers.
                while (true) {
                    ch = in.read();
                    inBytes.add(new Integer(ch));
                    ch1 = ch2;
                    ch2 = ch3;
                    ch3 = ch4;
                    ch4 = ch;
                    if (ch1 == '\r' && ch2 == '\n' && ch3 == '\r' && ch4 == '\n')
                        break;
                    if ((! postMethod) &&
                        (! in.ready()) &&
                        ch1 == -1 &&
                        ch2 == -1 &&
                        ch3 == '\r' &&
                        ch4 == '\n') {
                        inBytes.add(new Integer('\r'));
                        inBytes.add(new Integer('\n'));
                        break;
                byte[] byteArray = new byte[inBytes.size()];
                for (int i = 0; i < inBytes.size(); i++) {
                    Integer ich = (Integer) inBytes.get(i);
                    byteArray[i] = ich.byteValue();
                String headers = new String(byteArray);
                if (postMethod) {
                    String lcHeaders = headers.toLowerCase();
                    int i = lcHeaders.indexOf("content-length: ");
                    String contentLength = lcHeaders.substring(i + 16);
                    int j = contentLength.indexOf("\r\n");
                    contentLength = contentLength.substring(0, j);
                    int bodyLen = (new Integer(contentLength)).intValue();
                    for (int k = 0; k < bodyLen; k++) {
                        bodyLine = bodyLine + (new Character((char) in.read())).toString();
                String line = methodLine + "\r\n" + headers + bodyLine;
                if (traceRequests)
                    Log.current.println(line);
                if (postMethod)
                    processHttpPost();
                else
                    if (line.startsWith("GET /"))
                        processHttpGet(line.substring(4));
                    else {
                        Log.current.println("Invalid request = " + line);
                        throw new IOException();
             * Processes an HTTP GET method.
             * @param httpGetPath the path of the file to get.
             * @exception IOException if the file is not found.
            private void processHttpGet(String httpGetPath) throws IOException {
                int i = httpGetPath.indexOf(' ');
                if (i > 0)
                    httpGetPath = httpGetPath.substring(0, i);
                Log.current.println(methodLine + " from " + sock.getInetAddress().getHostName());
                i = httpGetPath.indexOf("cg?");
                if (i > 0) {
                    cycHtmlRequest(httpGetPath.substring(i + 3));
                    return;
                notFoundPath = httpGetPath;
                i = httpGetPath.indexOf('/');
                if (i < 0 || map == null) {
                    if (map == null || httpGetPath.endsWith(".jar")) {
                        for (int j = 0; j < dirs.size(); j++) {
                            String dir = (String) dirs.get(j);
                            String nativePath = dir + httpGetPath;
                            nativePath = nativePath.replace('/', File.separatorChar);
                            if (fileCache.containsKey(nativePath)) {
                                writeDataBytes((byte[]) fileCache.get(nativePath));
                                Log.current.println("...cached");
                                nbrCacheHits++;
                                nbrFilesServed++;
                                return;
                            try {
                                File f = new File(nativePath);
                                byte[] fileBytes = getBytes(new FileInputStream(f), f.length());
                                writeDataBytes(fileBytes);
                                if (fileCache.size() >= CACHE_CAPACITY)
                                    fileCache.clear();
                                fileCache.put(nativePath, fileBytes);
                                Log.current.println("...from " + nativePath);
                                nbrFilesServed++;
                                return;
                            catch (IOException e) {
                    throw new IOException();
                String jar = httpGetPath.substring(0, i);
                httpGetPath = httpGetPath.substring(i + 1);
                JarFile[] jfs = (JarFile[]) map.get(jar);
                if (jfs == null)
                    throw new IOException();
                for (i = 0; i < jfs.length; i++) {
                    JarEntry je = jfs.getJarEntry(httpGetPath);
    if (je == null)
    continue;
    writeDataBytes(getBytes(jfs[i].getInputStream(je), je.getSize()));
    nbrFilesServed++;
    return;
    throw new IOException();
    * Processes an HTTP POST method.
    * @exception IOException if the file is not found.
    private void processHttpPost() throws IOException {
    Log.current.println("POST " + bodyLine + " from " + sock.getInetAddress().getHostName());
    cycHtmlRequest(bodyLine);
    * Reads the specified number of bytes and always close the stream.
    * @param in the file to be read for subsequent downloading.
    * @param length the number of bytes to read from the file.
    * @return An array of bytes from the file.
    * @exception IOException if an error occurs when processing the file.
    private byte[] getBytes(InputStream in, long length) throws IOException {
    DataInputStream din = new DataInputStream(in);
    byte[] bytes = new byte[ (int) length];
    try {
    din.readFully(bytes);
    finally {
    din.close();
    return bytes;
    * Sends the HTML request to Cyc.
    * @param cycPath the portion of the URL which is given to the Cyc HTML server.
    private void cycHtmlRequest(String cycPath) {
    String request = sock.getInetAddress().getHostName() + "&" + cycPath + "#";
    System.out.println("request=" + request);
    ArrayList bytes = new ArrayList(10000);
    try {
    cycHtmlSocket = new Socket(cycHost, cycPort);
    System.out.println("cycHost=" + cycHost + " cycPort=" + cycPort);
    BufferedReader cycIn = new BufferedReader(new InputStreamReader(cycHtmlSocket.getInputStream()));
    PrintWriter cycOut = new PrintWriter(cycHtmlSocket.getOutputStream(), true);
    cycOut.println(request);
    cycOut.flush();
    int ch = 0;
    while (ch >= 0) {
    ch = cycIn.read();
    bytes.add(new Integer(ch));
    catch (Exception e) {
    Log.current.printStackTrace(e);
    byte[] byteArray = new byte[bytes.size()];
    for (int i = 0; i < bytes.size() - 1; i++) {
    Integer ich = (Integer) bytes.get(i);
    byteArray[i] = ich.byteValue();
    try {
    writeTextBytes(byteArray);
    catch (Exception e) {
    Log.current.println(e.getMessage());
    * Responds to the HTTP client with data content from the requested URL.
    * @param bytes the array of bytes from the URL.
    * @exception IOException if there is an error writing to the HTTP client.
    public void writeDataBytes(byte[] bytes) throws IOException {
    out.writeBytes("HTTP/1.1 200 OK\r\n");
    out.writeBytes("Server: Cyc WebServer\r\n");
    out.writeBytes("Connection: close\r\n");
    out.writeBytes("Content-Length: " + bytes.length + "\r\n");
    String prefix = (new String(bytes)).toLowerCase();
    if (prefix.indexOf("<html>") > -1)
    out.writeBytes("Content-Type: text/html\r\n\r\n");
    else
    out.writeBytes("Content-Type: application/java\r\n\r\n");
    out.write(bytes);
    out.flush();
    * Respond to the HTTP client with text content from the requested URL.
    * @param bytes the array of bytes from the URL.
    * @exception IOException if there is an error writing to the HTTP client.
    public void writeTextBytes(byte[] bytes) throws IOException {
    out.writeBytes("HTTP/1.1 200 OK\r\n");
    out.writeBytes("Server: Cyc WebServer\r\n");
    out.writeBytes("Connection: close\r\n");
    out.writeBytes("Content-Length: " + bytes.length + "\r\n");
    out.writeBytes("Content-Type: text/html\r\n\r\n");
    out.write(bytes);
    out.flush();
    * Gets properties governing the web server's behavior.
    private void getProperties() {
    port = DEFAULT_PORT;
    String portProperty = System.getProperty("org.opencyc.webserver.port", "");
    if (! portProperty.equalsIgnoreCase(""))
    port = (new Integer(portProperty)).intValue();
    Log.current.println("Listening on port " + port);
    cycPort = DEFAULT_CYC_PORT;
    String cycPortProperty = System.getProperty("org.opencyc.webserver.cycPort", "");
    if (! cycPortProperty.equalsIgnoreCase(""))
    cycPort = (new Integer(cycPortProperty)).intValue();
    Log.current.println("Cyc connections directed to port " + cycPort);
    String dirsProperty = System.getProperty("org.opencyc.webserver.dirs", "");
    dirs = new ArrayList(3);
    StringTokenizer st = new StringTokenizer(dirsProperty, ";", false);
    while (st.hasMoreTokens()) {
    String dir = st.nextToken();
    dirs.add(dir);
    trees = false;
    String treesProperty = System.getProperty("org.opencyc.webserver.trees", "");
    if (! treesProperty.equalsIgnoreCase(""))
    trees = true;
    traceRequests = false;
    String traceRequestsProperty = System.getProperty("org.opencyc.webserver.traceRequests", "");
    if (! traceRequestsProperty.equalsIgnoreCase("")) {
    traceRequests = true;
    Log.current.println("tracing requests");
    * Adds transitive Class-Path jars to jfs.
    * @param jar the jar file
    * @param jfs the list of jar files to serve.
    * @param dir the jar file directory.
    * @exception IOException if an I/O error has occurred with the jar file.
    private void addJar(String jar, ArrayList jfs, String dir) throws IOException {
    Log.current.println("Serving jar files from: " + dir + jar);
    JarFile jf = new JarFile(dir + jar);
    jfs.add(jf);
    Manifest man = jf.getManifest();
    if (man == null)
    return;
    Attributes attrs = man.getMainAttributes();
    if (attrs == null)
    return;
    String val = attrs.getValue(Attributes.Name.CLASS_PATH);
    if (val == null)
    return;
    dir = dir + jar.substring(0, jar.lastIndexOf(File.separatorChar) + 1);
    StringTokenizer st = new StringTokenizer(val);
    while (st.hasMoreTokens()) {
    addJar(st.nextToken().replace('/', File.separatorChar), jfs, dir);
    * Administrative accessor method that obtains list of directories from which files are served.
    public ArrayList getDirs() {
    return dirs;
    * Administrative method that updates the list of directories from which files are served.
    public synchronized void setDirs(ArrayList dirs) throws IOException {
    this.dirs = dirs;
    fileCache.clear();
    processDirectories();
    * Administrative accessor method that obtains number of files served.
    * @return The number of files served.
    public long getNbrFilesServed() {
    return nbrFilesServed;
    * Administrative accessor method that obtains number of files served from cache.
    * @return The number of files served from the cache.
    public long getNbrCacheHits() {
    return nbrCacheHits;
    * Administrative method that clears the file cache.
    public synchronized void clearFileCache() {
    Log.current.println("Clearing file cache");
    fileCache.clear();
    nbrFilesServed = 0;
    nbrCacheHits = 0;
    * Processes the directories from which files are served, expanding jar trees if
    * directed.
    * @exception IOException if problem occurs while processing the jar files.
    private void processDirectories() throws IOException {
    if (dirs.size() == 0)
    if (File.separatorChar == '\\')
    dirs.add(DEFAULT_WIN_DIR);
    else
    dirs.add(DEFAULT_DIR);
    Iterator directories = dirs.iterator();
    while (directories.hasNext())
    Log.current.println("Serving from " + directories.next());
    if (trees) {
    map = new HashMap();
    for (int j = 0; j < dirs.size(); j++) {
    String dir = (String) dirs.get(j);
    String[] files = new File(dir).list();
    for (int i = 0; i < files.length; i++) {
    String jar = files[i];
    if (!jar.endsWith(".jar"))
    continue;
    ArrayList jfs = new ArrayList(1);
    addJar(jar, jfs, dir);
    map.put(jar.substring(0, jar.length() - 4), jfs.toArray(new JarFile[jfs.size()]));
    * Provides the command line interface for creating an HTTP server.
    * The properties are:
    * <pre>
    * org.opencyc.webserver.port=<HTTP listening port>
    * </pre>
    * which defaults to 80.
    * <pre>
    * org.opencyc.webserver.cycPort=<Cyc connection port>
    * </pre>
    * which defaults to 3600.
    * <pre>
    * org.opencyc.webserver.dirs=<path>;<path> ... ;<path>
    * </pre>
    * with the argument enclosed in quotes if any path contains an
    * embedded space.
    * The default directory on Windows is C:
    * and the default on other systems is / the default
    * can be overridden with this property. By default, all files
    * under this directory (including all subdirectories) are served
    * up via HTTP. If the pathname of a file is <var>path</var> relative
    * to the top-level directory, then the file can be downloaded using
    * the URL
    * <pre>
    * http://<var>host</var>:<var>port</var>/<var>path</var>
    * </pre>
    * Caching of file contents is performed.
    * <pre>
    * org.opencyc.util.log=all
    * </pre>
    * If the all value is given, then all attempts to download files
    * are output.
    * <pre>
    * org.opencyc.webserver.traceRequests
    * </pre>
    * If this property has any value, then the client HTTP requests are
    * output.<p>
    * <pre>
    * org.opencyc.webserver.trees
    * </pre>
    * This property can be used to serve up individual files stored
    * within jar files in addition to the files that are served up by
    * default. If the property has any value, the server finds all jar files
    * in the top-level directory (not in subdirectories). For each
    * jar file, if the name of the jar file is <var>name</var>.jar, then any
    * individual file named <var>file</var> within that jar file (or within
    * the jar or zip files referenced transitively in the Class-Path manifest
    * attribute, can be downloaded using a URL of the form:
    * <pre>
    * http://<var>host</var>:<var>port</var>/<var>name</var>/<var>file</var>
    * </pre>
    * When this property has any value, an open file descriptor and cached
    * information are held for each jar file, for the life of the process.
    * @param args an unused array of command line arguments.
    public static void main(String[] args) {
    Log.makeLog();
    System.out.println("OpenCyc Web Server");
    try {
    // Launch thread to accept HTTP connections.
    current = new WebServer();
    current.start();
    catch (IOException e) {
    e.printStackTrace();
    * Just keep looping, spawning a new thread for each incoming request.
    public void run() {
    try {
    while (true) {
    // Launch thread to process one HTTP request.
    new Task(server.accept()).start();
    catch (IOException e) {
    e.printStackTrace();

    JLundan,
    I want to thank you for responding to the thread I started on the forum at java.sun.com. Your solution to my problem of needing to print the code of the html pages that the file I included generates was just what I was looking for. However, I have some further questions to ask, if you don't mind. To clarify my task I should say that your rephrasing of the problem is accurate: "You wan't to display the contents of the HTML file that the web server produces in response of client's request?"
    Yes, this is what I need to do, but also it needs to display the source code of that html file that the server produces in response to the client's request. Also, in this case, I am the client requesting that the server return some html file, and I'm not sure where the server is. But the webserver.java file that I shared on the forum is on my local machine. I was wondering if I could modify this webserver.java file at my home so that any html file the server returns to me would automatically display the source code. This is a school project of mine and I am stuck on this one thing here.
    Further, where would I put the "foo.html" file so it can be written to?
    FileOuputStream fos = new FileOutputStream("foo.html");
    fos.write(bytes);
    fos.close();
    Thanks so much for your help. I look forward to your response, at your convenience.
    Regards

  • ABAP WD, Read the source code of a html page

    Hi all,
    I have the URL link of .jsp page and I want to get the source code generated by this page to extract some data for my web dynpro.
    How do i solve this?
    Thanks

    Hi Antonio,
    not sure if i understand the question properly.
    You want to read html content of http site rendered via jsp.
    You can use cl_http_client
    to write a simple http client tool.
    This tool opens the page.  The html content is available to this class.
    You can extract the content here.
    See the attribute 'response' after making a call.
    regards
    Phil.

  • Where to get the source code of the owa_cookie.send procedure?

    I want to know where you get the source code of the owa_cookie.send procedure? I can only get the header of this package from ...\RDBMS\ADMIN\pubcook.sql. Could you paste the whole source code here and then I can modify it to set the 'httponly' attribute? I also have a problem that after changing the package, how to use the package I changed? Does it still a system package here? Or it has been changed to an user-defined package in database and I need to execute the package on the database for the web server?
    Thank you!

    Hi Arun,
    I am unable to see the pcui_gp components in the DTR ,I require this in order to get the source code of one of its component.
    Can you please tell me the step by step procedure getting those pcui_gp components from J2ee engine to the  dtr or  NWDI.
    If there are any documents on pcui_gp components exclusively please do forward to my mail id [email protected]
    Thansk and Regards,
    Anand.

  • How to view the source code of JavaFx component ?

    Hi everybody,
    I just want to know if it's possible to view the source code of the component Button (from JavaFx) and how to do it ?
    In fact, I don't really understand if JavaFx is entirely open source ?
    Thanks.

    I lack time right now to experiment, but I think you can get your goal just with CSS.
    Here are the variables I found for Button:
    Button
    borderFill: class javafx.scene.paint.Paint = (null)
    button: class javafx.scene.control.Button = Button
    colorBrightness: Float = 0.8156863
    cornerRadius: Float = 7.0
    fill: class javafx.scene.paint.Paint = (null)
    focusFill: class javafx.scene.paint.Paint = javafx.scene.paint.Color[red=0,green=147,blue=255,opacity=1.0]
    focusSize: Float = 1.4
    highlightFill: class javafx.scene.paint.Paint = (null)
    label: class javafx.scene.control.Label = LabeledImpl [id=-Label]
    paddingBottom: Float = 4.0
    paddingLeft: Float = 10.0
    paddingRight: Float = 10.0
    paddingTop: Float = 4.0
    shadowFill: class javafx.scene.paint.Paint = (null)
    textFill: class javafx.scene.paint.Paint = (null)
    textFont: class javafx.scene.text.Font = Font[name=Verdana, family=Verdana, style=, size=11.0]Try changing cornerRadius and focusFill/highlightFill, etc. Note that some discovered properties are not affected by CSS... Perhaps that's why there isn't an official doc about CSS styling currently.

  • How to get the source code of UI elements ?

    What is the way to get the source code of the elements used in qUnit Page for sap.m.List and all sap.m List Items ? I am looking to implement the same in my applications ?

    Hi Micheal,
    You can see the source code here for controls in sap.m.
    sap.m Explored
    Also for the link you provided, You can right click on the page and click on the View Page Source will show you the source code.
    Regards,
    KK

  • Need to find the source code for java.util.LinkedList

    Hello all,
    I'm new to the forums and I actually need the LinkedList source file as well as all the source files for all Java packages and libraries. Please post a link here if you can, or email me at [email protected]
    Thanks again!
    copter_man

    But those must be platform dependant, not really that
    interesting to look at. I have never felt any need to
    look at those at least.Wake up and smell the coffee, abbie! I read the source code all the time and constantly tell my students to do that, too.
    1. Java source code is not platform dependent. The original poster wanted to look at linked list code, how could that be platform dependent?
    2. It is the implementation of the SDK APIs, so by definition it is implementation dependent code, liable to change in a later version. So don't assume anything beyond what is claimed in the API documentation. However, sometimes the documentation is incomplete or ambiguous to you, and reading the source can provide some insight, however implementation dependent. (Light a candle or curse the darkness.)
    3. Why read source code? It's a good way to learn how to program. You see something in the API and ask: how'd they do that? Or you realize you want to do something broadly similar, but you can't reuse the source code.
    For example, Images are not Serializable, but suppose you want a small image that is part of an object to be serialized with the rest of the object without too much fuss (ie, without using javax.imageio). You notice ImageIcon is serializable, so you use it. (An ImageIcon has-an Image.) Then you wonder: how'd they do that? You read the source and then you know.
    You live, you learn,
    Nax

  • Customize interface without touching the source code

    My VP of of marketing is at it again. I have pasted in the exact email that he sent me. If anyone has ideas or suggestions or knows if Forms 9i has this built-in capability, please let me know.
    Thanks.
    Can you post this on metalink and see if someone at Oracle (or elsewhere) has an answer for us? Somehow, other LIMS developers are distributing LIMS products that allow their users to customize the interface without touching the source code -- no impact on their ability to take new releases. How do they do that?
    Here's my question:
    Anyone familiar with the Tools / Forms / Design this Form feature in MS Outlook? This allows a mere mortal to actually create and publish a custom Outlook form (could be a Contact, Task, Note, Journal, etc. form) across the organization. Is there such a capability built into Oracle9i Forms? In other words, can a developer easily build and distribute an Oracle software app such that the end-user can use an administrative tool to modify the interface/forms, add fields, change field names, move things around on the form, change colors, etc. -- without needing the Oracle Developer tool used by the original software developer, along with source code?
    Here's my original email from a few months ago:
    Our VP of marketing has been on my case about the ability to allow customers to "map" a form label (prompt) to a "custom" label of their choosing. The only way I know to do this is to create a "mapping" table and each time a form opens have code in the Post-Query trigger that changes the prompt of each column to the label that is in the "mapper" table. My fear here is Performance. Also, if the user closes that form and comes back to it - that logic has to be executed again - once again Performance. We have thought about the global variable idea, but we have over 100 tables with approx. 20 columns each. That's alot of globals to carry around. What's the overhead of carring around let's say 150 global variables?
    My questions to all of you are:
    1) Is anyone else doing this exact thing?
    2) If so, what is the performance hit?
    3) Is there a way to "remember" after the first time it paints - until the application is closed (not just that form) - other than global variables?
    4) Is there a solution already in place within Forms for this?
    5) Is there newer technology that has overcome this problem?
    My VP doesn't like the mapping idea. He wants to know isn't there a better way instead of mapping all the fields. Isn't there some simple utility provided by Oracle that allows the user to simply change the form labels (no, he's not talking about Oracle Developer). He is a real Outlook nut. So he's always comparing everything to how Outlook works. This is how it works in Outlook -- you click on Design Form, modify it, then install it on the machine. Surely Oracle must have something like this. He thinks we're asking the wrong question or not asking it in the right way. I'm not sure how else to ask it. Our users want to see "Date of Birth" spelled out instead of "DOB" as the label for a column on a form. Is there a way for them to take the fmx and change that label? Is there a better way other than storing this in a table and querying it up each time the form opens? Yes, I could use a global so I don't have to query it from the database every time, but I still have to evaluate every time the form is opened during that session to see which label I need to use and then set the prompt accordingly. Our VP doesn't like this, he wants this to be a one time change.
    Thanks so much for you help,
    Tina

    Hmmm.... either your VP of marketing or the users have too much time on their hands. ;-)
    I would go with a lookup table. If your database is responsive and you index the table by form name, you can retrieve a number of rows and setup the screen quickly enough that nobody would notice any time lag.
    If there aren't too many titles stored in the form, you could use a PLL library procedure and stuff all of them into a few globals -- just stack them into a single string separated by an odd character, like maybe chr(3). Then when the form is called again, it could first check to see if the globals exist, and parse the titles from there.
    But be careful about changing field titles. If they change DOB to Date of Birth, the length changes, and so you need to determine where the extra length goes. The title field must be wide enough and the text justification should be set properly.

  • All source codes of jmf documentation are missing ?

    Hello,
    I'am learnig jmf by reading the jmf documentation in the oracle website.
    But all source codes in jmf documentation are missing because the website is oracle, and not sun.
    For example, in this page http://www.oracle.com/technetwork/java/javase/documentation/swingjmf-176877.html ,
    the link of MDIApp.java source code is broken ( http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/MDIApp.java ).
    So where are all source code of jmf documentation ?
    Thank you.

    Hi,
    I am trying to learn Java Media Frame work and am looking for the source to MDIApp.java.
    The link is broken.
    Please can you guys post the source code.
    Thanks

  • Dbx cannot locate the (DLM) source codes correctly for 64bit app

    It's hard for me to prepare a test case. Because it seems for a simple "hello world" it works.
    The reason I raise this issue here is because my project was recently upgraded to compile with 64bit. And since then dbx cannot locate the source codes correctly, especially for some DLM codes. (sometimes it shows to "/usr/include/iso/..." which it should never be!). While it works fine on a 32bit compiled mode.
    Did anyone experience the similar situation and can share your idea?
    Thanks in advance.

    Can't think of any good reason why going to 64 bit would confuse dbx (except for unknown bug in dbx, which is not impossible).
    I'd first look for changes in your build - for example, 32-bit code used to go to bin/ directory, but 64-bit goes to bin/sparcv9, which happens to be a symlink somewhere else or something like that. Symlinks might sometimes confuse dbx, please read
    (dbx) help finding-filestopic (in dbx console, type "help finding-files").
    Since you are using CC 5.9 that generates DWARF info by default, location and even presence of .o files is not important. All debug info should be in the shared library itself.
    Here's another idea: inspect DWARF info by hand and see if it looks correct to you.
    $ dwarfdump a.out | lessLook for
                    DW_AT_name                  a.ccand
                    DW_AT_comp_dir              /home/maxim/tempThose two should give location of source file (/home/maxim/temp/a.cc in my case). Maybe this will give you some clue.

  • How to wrapp the source code?

    Dear all,
    I am building an application here and i do not want other developers to be able to see my source code of the packages,
    i heared that i can wrapp the source code but i do not know how
    any suggestions?
    thanks

    Hi,
    There's a tool for that which is shipped with Oracle itself. It's called 'wrap'. Read the docs for examples...
    But: Why do you want to do that? If you and your colleagues are working on the same project, I would beat you if I were the project leader. How should anyone resolve issues with your code in case of absence?
    Curious regards

  • Viewing the source code

    hi,
    I'm interested in doing some programming in Java but I'm having some real trouble just viewing the source code. First of all, I have a program I would like to look at and I have downloaded the binary files. However, after downloading the Java Development Kit, I still can't find a way to look at the actual source code. I have tried clicking everything in the C:\Program Files\Java\jdk1.6.0_12\bin file but with no avail. Is there a way to look at the actual source code? I've tried writing java but I really need examples in order to learn anything useful. Reading a HOWTO will only get me so far...
    In case you are wondering, the program I have downloaded is called iFreeBudget. Like I said earlier, it's programmed in Java and I have downloaded the binary files but I can't find a way to view the actual code the programmer used to make the program.
    Thanks for your time!
    Mike

    I've tried writing java but I really need examples in order to learn anything useful. Reading a HOWTO will only get me so far...I'm not exactly sure what you mean by a HOWTO but in addition to looking at examples you really should go through the tutorials here .
    From your message I inferred that you are a complete java beginner. I think you will save yourself much confusion and trouble if you take the time to go through the tutorials.
    There are code examples, instructions on how to setup and compile things, and all kinds of explanations of things that you will need to know.

  • How do i save the source code of a javascript alert in safari?

    I am trying to save the source code of the javascript alert in safari but the menu items blank out.
    Is this even possible?
    dave

    Eventhought it is a usefull function which i did not know about it is not helping me. This is what hapens.
    I request an url and get a javascript alert back from the server. The javascript alert triggers that is i get a popup where I can only press ok. If i do not press ok i can not do anything else. the safari menu's are greyed out. if i do press ok i get redirected and i can not read the javascript page with your suggestion.
    what i want is read the source for that javascript alert so i know what it says (my filemaker database that is) but because that option is greyed out i am stuck.
    here is the link i use to get the javascript popup:
    https://www.login.alex.nl/klanten/portfolio/portefeuille-xls.asp?print=true
    the javascript says i am not loged in.
    if i get this javascript alert in firefox i can ask for the sourcecode, read it and do stuff that is log in. I just do not understand how i can change safari so it does the same thing as firefox.
    thanks again

Maybe you are looking for

  • T.code FF7A: how to see old and NEW open items?

    Hi All, I've filled the "Cash Managemeng Group" in the master data of a Customer. The report Cash Manag.& Forecast doesn't update its old open line Items. Only the documents successive to the insertion of the "Cash Managemeng Group" in the master dat

  • EvDRE Report with multiple columns

    Hi, I need to load Actual Sales data for that I am creating an input schedule using EvDRE. I created a 3x3 schedule. But while doing that I get the following error in A1. #ERR: Duplicate <dimension> on axis, col# 2 I believe this is because Dimension

  • Can any one help me in configuring internet on E220R

    Hi All, I am trying to configure internet on E220R and on Solaris 8. I am having a Linksys router and default IP for my router is 192.169.15.1 I am using Roadrunner High speed broad band connection. Subnet mask : 255.255.255.0 Default Gateway : 192.1

  • Bulk Load API Status

    Hi, I'm using Oracle Endeca 2.3. I encountered a problem in data integrator, Some batch of records were missing in the Front end and when I checked the status of Graph , It Showed "Graph Executed sucessfully". So, I've connected the Bulk loader to "U

  • PP CS6 give "general error" when importing MXF files

    Hi there, I'm a videographer at a school and they recently purchased CS6 for me to use to edit footage. I shoot on a Sony PXW-X70. However, anytime I attempt to import using Media Browser (or the input feature) any files from the camera, PP gives me