Source Code Cross Referenced for LoggedInputStream.java in  » Installer » IzPack » com » izforge » izpack » installer » 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 » Installer » IzPack » com.izforge.izpack.installer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003:         *
004:         * http://izpack.org/
005:         * http://izpack.codehaus.org/
006:         *
007:         * Copyright 2007 Vladimir Ralev
008:         *
009:         * Licensed under the Apache License, Version 2.0 (the "License");
010:         * you may not use this file except in compliance with the License.
011:         * You may obtain a copy of the License at
012:         *
013:         *     http://www.apache.org/licenses/LICENSE-2.0
014:         *
015:         * Unless required by applicable law or agreed to in writing, software
016:         * distributed under the License is distributed on an "AS IS" BASIS,
017:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:         * See the License for the specific language governing permissions and
019:         * limitations under the License.
020:         */
021:
022:        package com.izforge.izpack.installer;
023:
024:        import java.io.IOException;
025:        import java.io.InputStream;
026:
027:        import com.izforge.izpack.Pack;
028:
029:        /**
030:         * 
031:         * Wraps an InputStream in order to track how much bytes are being read, and
032:         * then updates the progress dialog. When the stream is opened the progress 
033:         * dialog shows up. When the stream is closed the dialog is disposed. Make sure
034:         * you are closing the streams.
035:         * 
036:         * @author <a href="vralev@redhat.com">Vladimir Ralev</a>
037:         * @version $Revision: 1.1 $
038:         */
039:        public class LoggedInputStream extends InputStream {
040:            private long bytesRead = 0;
041:            private InputStream is;
042:            private DownloadPanel downloader;
043:            // private WebAccessor webAccessor;  // Unused
044:            private boolean cancelled = false;
045:            private long lastTime = -1;
046:            private long lastBytes = -1;
047:
048:            public void setCancelled(boolean cancel) {
049:                cancelled = cancel;
050:            }
051:
052:            public LoggedInputStream(InputStream is, WebAccessor webAccessor) {
053:                if (is == null)
054:                    throw new RuntimeException("Unable to connect");
055:                this .is = is;
056:                // this.webAccessor = webAccessor;
057:
058:                String sizeStr;
059:                if (webAccessor.getContentLength() > 0)
060:                    sizeStr = "("
061:                            + Pack.toByteUnitsString(webAccessor
062:                                    .getContentLength()) + ")";
063:                else
064:                    sizeStr = "";
065:
066:                downloader = new DownloadPanel(this );
067:                downloader.setTitle("Downloading");
068:                downloader.setFileLabel(webAccessor.getUrl() + " " + sizeStr);
069:                downloader.setLocationRelativeTo(null);
070:                downloader.setVisible(true);
071:                if (webAccessor.getContentLength() > 0) {
072:                    downloader.setProgressMax(webAccessor.getContentLength());
073:                    downloader.setProgressCurrent(0);
074:                }
075:            }
076:
077:            public int available() throws IOException {
078:                return is.available();
079:            }
080:
081:            public void close() throws IOException {
082:                downloader.setVisible(false);
083:                downloader.dispose();
084:                is.close();
085:            }
086:
087:            public synchronized void mark(int readlimit) {
088:                is.mark(readlimit);
089:            }
090:
091:            public boolean markSupported() {
092:                return is.markSupported();
093:            }
094:
095:            public synchronized void reset() throws IOException {
096:                is.reset();
097:            }
098:
099:            public long skip(long n) throws IOException {
100:                return is.skip(n);
101:            }
102:
103:            public int read(byte[] b, int off, int len) throws IOException {
104:                int bytes = is.read(b, off, len);
105:                if (bytes > 0)
106:                    bytesRead += bytes;
107:                update();
108:                return bytes;
109:            }
110:
111:            public int read(byte[] b) throws IOException {
112:                int bytes = is.read(b);
113:                if (bytes > 0)
114:                    bytesRead += bytes;
115:                update();
116:                return bytes;
117:            }
118:
119:            public long getBytesRead() {
120:                return bytesRead;
121:            }
122:
123:            public int read() throws IOException {
124:                int bytes = is.read();
125:                if (bytes > 0)
126:                    bytesRead += 1;
127:                update();
128:                return bytes;
129:            }
130:
131:            private void update() {
132:                if (lastTime > 0) {
133:                    long currTime = System.currentTimeMillis();
134:                    long diff = currTime - lastTime;
135:                    if (diff > 800) {
136:                        double bps = (double) (bytesRead - lastBytes)
137:                                / ((double) (diff) / 1000.);
138:                        downloader.setStatusLabel(Pack.toByteUnitsString(Math
139:                                .round(bps))
140:                                + "/s");
141:                        lastTime = currTime;
142:                        lastBytes = bytesRead;
143:                    }
144:                } else {
145:                    lastTime = System.currentTimeMillis();
146:                    lastBytes = bytesRead;
147:                }
148:                downloader.setProgressCurrent((int) bytesRead);
149:                if (cancelled)
150:                    throw new RuntimeException("Cancelled");
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.