Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/cdsadapter/com.ibm.cds/src/com/ibm/cds/CDSBundleEntry.java
12910 views
1
/*******************************************************************************
2
* Copyright (c) 2006, 2018 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
package com.ibm.cds;
24
25
import java.io.IOException;
26
import java.io.InputStream;
27
import java.net.URL;
28
29
import org.eclipse.osgi.storage.bundlefile.BundleEntry;
30
31
/**
32
* A bundle entry for a class that is found in the shared classes cache
33
*/
34
public class CDSBundleEntry extends BundleEntry {
35
String path;
36
byte[] classbytes;
37
BundleEntry wrapped;
38
39
/**
40
* The constructor
41
* @param path the path to the class file
42
* @param classbytes the magic cookie bytes for the class in the shared cache
43
* @param wrapped the actual bundleEntry where the class comes from
44
*/
45
public CDSBundleEntry(String path, byte[] classbytes, BundleEntry wrapped) {
46
super();
47
this.path = path;
48
this.classbytes = classbytes;
49
this.wrapped = wrapped;
50
}
51
52
/*
53
* (non-Javadoc)
54
* @see org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry#getFileURL()
55
* uses the wrapped bundle file to get the actual file url to the content of
56
* the class on disk.
57
*
58
* This should is likely never to be called.
59
*/
60
public URL getFileURL() {
61
return wrapped.getFileURL();
62
}
63
64
/*
65
* (non-Javadoc)
66
* @see org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry#getInputStream()
67
* wraps the classbytes into a ByteArrayInputStream. This should not be used
68
* by classloading.
69
*/
70
public InputStream getInputStream() throws IOException {
71
// someone is trying to get the real bytes of the class file!!
72
// just return the entry from the wrapped file instead of the magic cookie
73
return wrapped.getInputStream();
74
}
75
76
/*
77
* (non-Javadoc)
78
* @see org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry#getBytes()
79
* if classbytes is not null, it returns the magic cookie for the shared class. This is used to define
80
* the class during class loading.
81
* if classbytes is null, it gets the contents from actual BundleEntry and caches it in classbytes.
82
*/
83
public byte[] getBytes() throws IOException {
84
if (classbytes == null) {
85
classbytes = wrapped.getBytes();
86
}
87
return classbytes;
88
}
89
90
/*
91
* (non-Javadoc)
92
* @see org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry#getLocalURL()
93
* uses the wrapped bundle file to get the actual local url to the content of
94
* the class on disk.
95
*
96
* This should is likely never to be called.
97
*/
98
public URL getLocalURL() {
99
return wrapped.getLocalURL();
100
}
101
102
public String getName() {
103
return path;
104
}
105
106
public long getSize() {
107
return wrapped.getSize();
108
}
109
110
public long getTime() {
111
return wrapped.getTime();
112
}
113
}
114
115
116