Source Code Cross Referenced for FileStoreRIF.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » com » sun » media » jai » opimage » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » Java Advanced Imaging » com.sun.media.jai.opimage 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: FileStoreRIF.java,v $
003:         *
004:         * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Use is subject to license terms.
007:         *
008:         * $Revision: 1.2 $
009:         * $Date: 2005/12/02 01:51:26 $
010:         * $State: Exp $
011:         */
012:        package com.sun.media.jai.opimage;
013:
014:        import com.sun.media.jai.codec.ImageEncodeParam;
015:        import java.awt.RenderingHints;
016:        import java.awt.image.RenderedImage;
017:        import java.awt.image.renderable.ParameterBlock;
018:        import java.awt.image.renderable.RenderedImageFactory;
019:        import java.io.BufferedOutputStream;
020:        import java.io.FileOutputStream;
021:        import java.io.FileNotFoundException;
022:        import java.io.RandomAccessFile;
023:        import java.io.IOException;
024:        import java.io.OutputStream;
025:        import javax.media.jai.JAI;
026:        import javax.media.jai.OperationRegistry;
027:        import javax.media.jai.PlanarImage;
028:        import javax.media.jai.RenderedImageAdapter;
029:        import javax.media.jai.registry.RIFRegistry;
030:        import javax.media.jai.util.ImagingListener;
031:        import com.sun.media.jai.codec.SeekableOutputStream;
032:        import com.sun.media.jai.util.ImageUtil;
033:
034:        /**
035:         * @see javax.media.jai.operator.FileDescriptor
036:         *
037:         * @since EA4
038:         *
039:         */
040:        public class FileStoreRIF implements  RenderedImageFactory {
041:            /** The default file format. */
042:            private static String DEFAULT_FORMAT = "tiff";
043:
044:            /** Constructor. */
045:            public FileStoreRIF() {
046:            }
047:
048:            /*
049:             * Private class which merely adds a finalize() method to close
050:             * the associated stream.
051:             */
052:            private class FileStoreImage extends RenderedImageAdapter {
053:                private OutputStream stream;
054:
055:                /*
056:                 * Create the object and cache the stream.
057:                 */
058:                public FileStoreImage(RenderedImage image, OutputStream stream) {
059:                    super (image);
060:                    this .stream = stream;
061:                }
062:
063:                /*
064:                 * Close the stream.
065:                 */
066:                public void dispose() {
067:                    try {
068:                        stream.close();
069:                    } catch (IOException e) {
070:                        // Ignore it ...
071:                    }
072:                    super .dispose();
073:                }
074:            }
075:
076:            /**
077:             * Stores an image to a file.
078:             */
079:            public RenderedImage create(ParameterBlock paramBlock,
080:                    RenderingHints renderHints) {
081:                ImagingListener listener = ImageUtil
082:                        .getImagingListener(renderHints);
083:
084:                // Retrieve the file path.
085:                String fileName = (String) paramBlock.getObjectParameter(0);
086:
087:                // Retrieve the file format preference.
088:                String format = (String) paramBlock.getObjectParameter(1);
089:
090:                // TODO: If format is null get format name from file extension.
091:
092:                // If the format is still null use the default format.
093:                if (format == null) {
094:                    format = DEFAULT_FORMAT;
095:                }
096:
097:                // Retrieve the ImageEncodeParam (which may be null).
098:                ImageEncodeParam param = null;
099:                if (paramBlock.getNumParameters() > 2) {
100:                    param = (ImageEncodeParam) paramBlock.getObjectParameter(2);
101:                }
102:
103:                // Create a FileOutputStream from the file name.
104:                OutputStream stream = null;
105:                try {
106:                    if (param == null) {
107:                        // Use a BufferedOutputStream for greater efficiency
108:                        // since no compression is occurring.
109:                        stream = new BufferedOutputStream(new FileOutputStream(
110:                                fileName));
111:                    } else {
112:                        // Use SeekableOutputStream to avoid temp cache file
113:                        // in case of compression.
114:                        stream = new SeekableOutputStream(new RandomAccessFile(
115:                                fileName, "rw"));
116:                    }
117:                } catch (FileNotFoundException e) {
118:                    String message = JaiI18N.getString("FileLoadRIF0")
119:                            + fileName;
120:                    listener.errorOccurred(message, e, this , false);
121:                    //            e.printStackTrace();
122:                    return null;
123:                } catch (SecurityException e) {
124:                    String message = JaiI18N.getString("FileStoreRIF0");
125:                    listener.errorOccurred(message, e, this , false);
126:                    //            e.printStackTrace();
127:                    return null;
128:                }
129:
130:                // Add the operation to the DAG.
131:                ParameterBlock pb = new ParameterBlock();
132:                pb.addSource(paramBlock.getSource(0));
133:                pb.add(stream).add(format).add(param);
134:
135:                // Get the default registry.
136:                OperationRegistry registry = (renderHints == null) ? null
137:                        : (OperationRegistry) renderHints
138:                                .get(JAI.KEY_OPERATION_REGISTRY);
139:
140:                PlanarImage im = new FileStoreImage(RIFRegistry.create(
141:                        registry, "encode", pb, renderHints), stream);
142:
143:                return im;
144:            }
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.