Path: blob/master/cdsadapter/com.ibm.cds/src/com/ibm/cds/CDSBundleEntry.java
12910 views
/*******************************************************************************1* Copyright (c) 2006, 2018 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122package com.ibm.cds;2324import java.io.IOException;25import java.io.InputStream;26import java.net.URL;2728import org.eclipse.osgi.storage.bundlefile.BundleEntry;2930/**31* A bundle entry for a class that is found in the shared classes cache32*/33public class CDSBundleEntry extends BundleEntry {34String path;35byte[] classbytes;36BundleEntry wrapped;3738/**39* The constructor40* @param path the path to the class file41* @param classbytes the magic cookie bytes for the class in the shared cache42* @param wrapped the actual bundleEntry where the class comes from43*/44public CDSBundleEntry(String path, byte[] classbytes, BundleEntry wrapped) {45super();46this.path = path;47this.classbytes = classbytes;48this.wrapped = wrapped;49}5051/*52* (non-Javadoc)53* @see org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry#getFileURL()54* uses the wrapped bundle file to get the actual file url to the content of55* the class on disk.56*57* This should is likely never to be called.58*/59public URL getFileURL() {60return wrapped.getFileURL();61}6263/*64* (non-Javadoc)65* @see org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry#getInputStream()66* wraps the classbytes into a ByteArrayInputStream. This should not be used67* by classloading.68*/69public InputStream getInputStream() throws IOException {70// someone is trying to get the real bytes of the class file!!71// just return the entry from the wrapped file instead of the magic cookie72return wrapped.getInputStream();73}7475/*76* (non-Javadoc)77* @see org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry#getBytes()78* if classbytes is not null, it returns the magic cookie for the shared class. This is used to define79* the class during class loading.80* if classbytes is null, it gets the contents from actual BundleEntry and caches it in classbytes.81*/82public byte[] getBytes() throws IOException {83if (classbytes == null) {84classbytes = wrapped.getBytes();85}86return classbytes;87}8889/*90* (non-Javadoc)91* @see org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry#getLocalURL()92* uses the wrapped bundle file to get the actual local url to the content of93* the class on disk.94*95* This should is likely never to be called.96*/97public URL getLocalURL() {98return wrapped.getLocalURL();99}100101public String getName() {102return path;103}104105public long getSize() {106return wrapped.getSize();107}108109public long getTime() {110return wrapped.getTime();111}112}113114115116