Source Code Cross Referenced for TarFileExporter.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » internal » wizards » datatransfer » 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 » IDE Eclipse » ui ide » org.eclipse.ui.internal.wizards.datatransfer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.wizards.datatransfer;
011:
012:        import java.io.BufferedOutputStream;
013:        import java.io.FileNotFoundException;
014:        import java.io.FileOutputStream;
015:        import java.io.IOException;
016:        import java.io.InputStream;
017:        import java.net.URI;
018:        import java.util.zip.GZIPOutputStream;
019:
020:        import org.eclipse.core.filesystem.EFS;
021:        import org.eclipse.core.resources.IFile;
022:        import org.eclipse.core.resources.IResource;
023:        import org.eclipse.core.resources.ResourceAttributes;
024:        import org.eclipse.core.runtime.CoreException;
025:
026:        /**
027:         * Exports resources to a .tar.gz file.
028:         *
029:         * @since 3.1
030:         */
031:        public class TarFileExporter implements  IFileExporter {
032:            private TarOutputStream outputStream;
033:            private GZIPOutputStream gzipOutputStream;
034:
035:            /**
036:             *	Create an instance of this class.
037:             *
038:             *	@param filename java.lang.String
039:             *	@param compress boolean
040:             *	@exception java.io.IOException
041:             */
042:            public TarFileExporter(String filename, boolean compress)
043:                    throws IOException {
044:                if (compress) {
045:                    gzipOutputStream = new GZIPOutputStream(
046:                            new FileOutputStream(filename));
047:                    outputStream = new TarOutputStream(
048:                            new BufferedOutputStream(gzipOutputStream));
049:                } else {
050:                    outputStream = new TarOutputStream(
051:                            new BufferedOutputStream(new FileOutputStream(
052:                                    filename)));
053:                }
054:            }
055:
056:            /**
057:             *	Do all required cleanup now that we're finished with the
058:             *	currently-open .tar.gz
059:             *
060:             *	@exception java.io.IOException
061:             */
062:            public void finished() throws IOException {
063:                outputStream.close();
064:                if (gzipOutputStream != null) {
065:                    gzipOutputStream.close();
066:                }
067:            }
068:
069:            /**
070:             *	Write the contents of the file to the tar archive.
071:             *
072:             *	@param entry
073:             *	@param contents
074:             *  @exception java.io.IOException
075:             *  @exception org.eclipse.core.runtime.CoreException
076:             */
077:            private void write(TarEntry entry, IFile contents)
078:                    throws IOException, CoreException {
079:                final URI location = contents.getLocationURI();
080:                if (location == null) {
081:                    throw new FileNotFoundException(contents.getFullPath()
082:                            .toOSString());
083:                }
084:
085:                InputStream contentStream = contents.getContents(false);
086:                entry.setSize(EFS.getStore(location).fetchInfo().getLength());
087:                outputStream.putNextEntry(entry);
088:                try {
089:                    int n;
090:                    byte[] readBuffer = new byte[4096];
091:                    while ((n = contentStream.read(readBuffer)) > 0) {
092:                        outputStream.write(readBuffer, 0, n);
093:                    }
094:                } finally {
095:                    if (contentStream != null) {
096:                        contentStream.close();
097:                    }
098:                }
099:
100:                outputStream.closeEntry();
101:            }
102:
103:            /**
104:             *  Write the passed resource to the current archive.
105:             *
106:             *  @param resource org.eclipse.core.resources.IFile
107:             *  @param destinationPath java.lang.String
108:             *  @exception java.io.IOException
109:             *  @exception org.eclipse.core.runtime.CoreException
110:             */
111:            public void write(IFile resource, String destinationPath)
112:                    throws IOException, CoreException {
113:
114:                TarEntry newEntry = new TarEntry(destinationPath);
115:                if (resource.getLocalTimeStamp() != IResource.NULL_STAMP) {
116:                    newEntry.setTime(resource.getLocalTimeStamp() / 1000);
117:                }
118:                ResourceAttributes attributes = resource
119:                        .getResourceAttributes();
120:                if (attributes != null && attributes.isExecutable()) {
121:                    newEntry.setMode(newEntry.getMode() | 0111);
122:                }
123:                if (attributes != null && attributes.isReadOnly()) {
124:                    newEntry.setMode(newEntry.getMode() & ~0222);
125:                }
126:                write(newEntry, resource);
127:            }
128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.