Source Code Cross Referenced for AntivirusStream.java in  » Net » hyperpool-0.4.0 » vicazh » hyperpool » stream » net » http » html » 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 » Net » hyperpool 0.4.0 » vicazh.hyperpool.stream.net.http.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package vicazh.hyperpool.stream.net.http.html;
002:
003:        import java.io.*;
004:        import java.net.*;
005:        import java.text.*;
006:        import java.util.*;
007:        import java.util.logging.*;
008:        import vicazh.hyperpool.Start;
009:        import vicazh.hyperpool.stream.*;
010:        import vicazh.hyperpool.stream.net.http.*;
011:        import vicazh.hyperpool.stream.Stream;
012:
013:        public class AntivirusStream extends ServerStream {
014:
015:            public AntivirusStream() {
016:            }
017:
018:            private String name;
019:
020:            public String getName() {
021:                return name;
022:            }
023:
024:            public void setName(String name) {
025:                this .name = name;
026:            }
027:
028:            private String ver;
029:
030:            public String getVer() {
031:                return ver;
032:            }
033:
034:            public void setVer(String ver) {
035:                this .ver = ver;
036:            }
037:
038:            private String time;
039:
040:            public String getTime() {
041:                return time;
042:            }
043:
044:            public void setTime(String time) {
045:                this .time = time;
046:            }
047:
048:            private File file;
049:
050:            private Socket socket;
051:
052:            private OutputStream av;
053:
054:            private InputStream in;
055:
056:            private OutputStream out;
057:
058:            private Date start;
059:
060:            AntivirusStream(Session session, OutputStream outputstream) {
061:                super (session, outputstream);
062:            }
063:
064:            private AntivirusClamAVConnection c;
065:
066:            private boolean status;
067:
068:            public void write(int b) throws IOException {
069:                if (!status) {
070:                    status = true;
071:                    if (session.getClient().getMethod() != null
072:                            && !session.getClient().getMethod()
073:                                    .equalsIgnoreCase("CONNECT")) {
074:                        try {
075:                            c = (AntivirusClamAVConnection) ((Stream) ((AntivirusService) connection.element).clamservice
076:                                    .get(null)).connection;
077:                            // c.getClient().write("PING\n".getBytes());
078:                            c.getClient().write("STREAM\n".getBytes());
079:                            c.getClient().flush();
080:                            synchronized (c) {
081:                                if (c.result == null)
082:                                    try {
083:                                        c.wait();
084:                                    } catch (InterruptedException e) {
085:                                    }
086:                            }
087:                            StringTokenizer st = new StringTokenizer(c.result);
088:                            st.nextToken();
089:                            socket = new Socket(
090:                                    ((AntivirusService) connection.element).outservice
091:                                            .getHost(), Integer.parseInt(st
092:                                            .nextToken()));
093:
094:                            socket
095:                                    .setSoTimeout(((AntivirusService) connection.element).timeout);
096:                            av = new BufferedOutputStream(socket
097:                                    .getOutputStream());
098:                            c.result = null;
099:                            file = File
100:                                    .createTempFile(
101:                                            ((AntivirusService) connection.element).prefix,
102:                                            null);
103:                            out = new BufferedOutputStream(
104:                                    new FileOutputStream(file));
105:                            in = new BufferedInputStream(new FileInputStream(
106:                                    file));
107:                            outputstream = new NullStream(outputstream);
108:                        } catch (Exception e) {
109:                            try {
110:                                c.getClient().flush();
111:                            } catch (Exception ex) {
112:                            }
113:                            try {
114:                                c.getClient().close();
115:                            } catch (Exception ex) {
116:                            }
117:                            throw new IOException("ClamAV connection error");
118:                        }
119:                    }
120:                }
121:                if (out != null)
122:                    out.write(b);
123:                super .write(b);
124:            }
125:
126:            private long len;
127:
128:            public void content(int i) throws IOException {
129:                if (out != null) {
130:                    av.write(i);
131:                    if (len == ((AntivirusService) connection.element)
132:                            .getBuffer()) {
133:                        while (in.available() > ((AntivirusService) connection.element)
134:                                .getBuffer()) {
135:                            Thread.yield();
136:                            ((NullStream) outputstream).outputstream.write(in
137:                                    .read());
138:                        }
139:                    } else
140:                        len++;
141:                }
142:                super .content(i);
143:            }
144:
145:            public void flush() throws IOException {
146:                super .flush();
147:                if (out == null)
148:                    return;
149:                av.flush();
150:                out.flush();
151:            }
152:
153:            private String text;
154:
155:            public String getText() {
156:                return text;
157:            }
158:
159:            public void setText(String text) {
160:                this .text = text;
161:            }
162:
163:            private String title;
164:
165:            public String getTitle() {
166:                return title;
167:            }
168:
169:            public void setTitle(String title) {
170:                this .title = title;
171:            }
172:
173:            private String message;
174:
175:            public String getMessage() {
176:                return message;
177:            }
178:
179:            public void setMessage(String message) {
180:                this .message = message;
181:            }
182:
183:            public void end() {
184:                super .end();
185:                if (out == null)
186:                    return;
187:                try {
188:                    av.flush();
189:                } catch (Exception e) {
190:                }
191:                try {
192:                    av.close();
193:                } catch (Exception e) {
194:                }
195:                try {
196:                    socket.close();
197:                } catch (Exception e) {
198:                }
199:                try {
200:                    out.flush();
201:                } catch (Exception e) {
202:                }
203:                try {
204:                    out.close();
205:                } catch (Exception e) {
206:                }
207:                outputstream = ((NullStream) outputstream).outputstream;
208:                synchronized (c) {
209:                    if (c.result == null && !c.c)
210:                        try {
211:                            c.wait();
212:                        } catch (InterruptedException e) {
213:                        }
214:                }
215:                try {
216:                    c.getClient().flush();
217:                } catch (Exception e) {
218:                }
219:                try {
220:                    c.getClient().close();
221:                } catch (Exception e) {
222:                }
223:                if (c.result == null) {
224:                    try {
225:                        in.close();
226:                    } catch (Exception e) {
227:                    }
228:                    file.delete();
229:                    throw new BreakException();
230:                } else if (c.result.contains("ERROR")) {
231:                    try {
232:                        in.close();
233:                    } catch (Exception e) {
234:                    }
235:                    file.delete();
236:                    throw new RuntimeException(c.result);
237:                } else if (c.result.equals("stream: OK")) {
238:                    try {
239:                        int i;
240:                        while ((i = in.read()) != -1) {
241:                            Thread.yield();
242:                            outputstream.write(i);
243:                        }
244:                    } catch (IOException e) {
245:                    }
246:                    try {
247:                        in.close();
248:                    } catch (Exception e) {
249:                    }
250:                    file.delete();
251:                } else {
252:                    try {
253:                        in.close();
254:                    } catch (Exception e) {
255:                    }
256:                    file.delete();
257:                    start = new Date();
258:                    StringTokenizer st = new StringTokenizer(c.result);
259:                    st.nextToken();
260:                    text = st.nextToken();
261:                    try {
262:                        ((AntivirusService) connection.element).store(session,
263:                                start);
264:                    } catch (FileNotFoundException e) {
265:                        Start.logger.log(Level.SEVERE, e.getMessage(), e);
266:                    }
267:                    if (len < ((AntivirusService) connection.element)
268:                            .getBuffer()) {
269:                        name = Start.NAME;
270:                        ver = Start.VERSION;
271:                        Locale locale = session.getClient().getLocale();
272:                        time = DateFormat.getDateTimeInstance(
273:                                DateFormat.DEFAULT, DateFormat.DEFAULT, locale)
274:                                .format(start);
275:                        title = ResourceBundle.getBundle(
276:                                ((AntivirusService) connection.element).base,
277:                                locale,
278:                                ((AntivirusService) connection.element).loader)
279:                                .getString("antivirus");
280:                        message = ResourceBundle.getBundle(
281:                                ((AntivirusService) connection.element).base,
282:                                locale,
283:                                ((AntivirusService) connection.element).loader)
284:                                .getString("virus");
285:                        try {
286:                            XMLStream cs = (XMLStream) ((Stream) new XMLService(
287:                                    this ).get(outputstream)).outputstream;
288:                            cs.head("", ((AntivirusService) connection.element)
289:                                    .getUrl(), "");
290:                            cs.header();
291:                            synchronized (cs.session.getServer()) {
292:                                if (!cs.session.getServer().isEnd)
293:                                    try {
294:                                        cs.session.getServer().wait();
295:                                    } catch (InterruptedException e) {
296:                                    }
297:                            }
298:                        } catch (IOException e) {
299:                            Start.logger.log(Level.SEVERE, e.getMessage(), e);
300:                        }
301:                    } else {
302:                        throw new BreakException();
303:                    }
304:                }
305:            }
306:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.