Source Code Cross Referenced for DbUtil.java in  » Portal » Open-Portal » com » sun » portal » search » db » 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 » Portal » Open Portal » com.sun.portal.search.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved. 
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms. 
004:         */
005:
006:        package com.sun.portal.search.db;
007:
008:        import java.io.File;
009:        import java.security.*;
010:
011:        public class DbUtil {
012:
013:            public static final int MD5_BYTES = 16;
014:
015:            public static int hex2uint32(byte data[]) {
016:                int v = 0;
017:                int lim = Math.min(8, data.length);
018:                for (int i = 0; i < lim; i++)
019:                    v |= ((int) (data[i] & 0xf)) << ((7 - i) * 4);
020:                return v & 0x7fff;
021:            }
022:
023:            /** @return canonical, absolute form of fn (relative to cwd if fn is relative) */
024:            public static String absolute_path(String fn) throws Exception {
025:                return new File(fn).getCanonicalPath();
026:            }
027:
028:            /** @return the directory containing this path */
029:            public static String path2directory(String path) throws Exception {
030:                File fp = new File(path);
031:                if (fp.isDirectory())
032:                    return fp.toString();
033:                String parent = new File(path).getParent();
034:                return parent;
035:            }
036:
037:            /** @return address of path relative to base */
038:            public static String relative_path(String base, String path)
039:                    throws Exception {
040:                File fp = new File(path);
041:                if (fp.isAbsolute())
042:                    return fp.getCanonicalPath();
043:                if (base.charAt(base.length() - 1) != File.separatorChar
044:                        && path.charAt(0) != File.separatorChar)
045:                    base += File.separator;
046:                return base + path;
047:            }
048:
049:            /** @return address of path relative to base */
050:            public static String absolute_path(String base, String path)
051:                    throws Exception {
052:                File fp = new File(path);
053:                if (fp.isAbsolute())
054:                    return fp.getCanonicalPath();
055:                File fb = new File(base);
056:                //return new File(fb.getCanonicalFile(), path).toString();
057:                return new File(base, path).toString();
058:            }
059:
060:            /** @return a URL MD5 based db key */
061:            public static Datum key_create(String url) throws Exception {
062:                byte md5[] = new byte[MD5_BYTES + 1];
063:                System
064:                        .arraycopy(md5bytes(url.getBytes()), 0, md5, 0,
065:                                MD5_BYTES);
066:                md5[MD5_BYTES] = 0;
067:                return new Datum(md5);
068:            }
069:
070:            static byte[] dotPer = { '.', 'p', 'e', 'r', };
071:
072:            public static Datum persist_key_create(String url) throws Exception {
073:                byte md5[] = new byte[MD5_BYTES + 5];
074:                System
075:                        .arraycopy(md5bytes(url.getBytes()), 0, md5, 0,
076:                                MD5_BYTES);
077:                System.arraycopy(dotPer, 0, md5, MD5_BYTES, 4);
078:                md5[MD5_BYTES + 4] = 0;
079:                return new Datum(md5);
080:            }
081:
082:            static MessageDigest md;
083:            static byte[] hexchars = { '0', '1', '2', '3', '4', '5', '6', '7',
084:                    '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
085:
086:            public static synchronized byte[] md5bytes(byte[] b)
087:                    throws Exception {
088:                byte[] res = new byte[32];
089:                if (md == null)
090:                    md = MessageDigest.getInstance("MD5");
091:                md.update(b);
092:                byte[] md5 = md.digest();
093:                for (int i = 0; i < 16; ++i) {
094:                    res[2 * i + 1] = hexchars[md5[i] & 0xf]; // hi nibble
095:                    res[2 * i] = hexchars[(md5[i] >> 4) & 0xf]; // lo nibble
096:                }
097:                return res;
098:            }
099:
100:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.