Java DataInputStream Read loadChecksum(Bundle b, BundleContext bc)

Here you can find the source of loadChecksum(Bundle b, BundleContext bc)

Description

Returns the stored checksum of the bundle.

License

Apache License

Parameter

Parameter Description
b the bundle whose checksum must be returned
bc the FileInstall's bundle context.

Return

the stored checksum of the bundle

Declaration

public static long loadChecksum(Bundle b, BundleContext bc) 

Method Source Code

//package com.java2s;
/*/*from w  w  w  .  j a  va2  s . com*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.io.DataInputStream;

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

public class Main {
    private static final String CHECKSUM_SUFFIX = ".checksum";

    /**
     * Returns the stored checksum of the bundle.
     * 
     * @param b
     *            the bundle whose checksum must be returned
     * @param bc
     *            the FileInstall's bundle context.
     * @return the stored checksum of the bundle
     */
    public static long loadChecksum(Bundle b, BundleContext bc) {
        String key = getBundleKey(b);
        File f = bc.getDataFile(key + CHECKSUM_SUFFIX);
        DataInputStream in = null;
        try {
            in = new DataInputStream(new FileInputStream(f));
            return in.readLong();
        } catch (Exception e) {
            return Long.MIN_VALUE;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    // Ignore
                }
            }
        }
    }

    private static String getBundleKey(Bundle b) {
        return Long.toString(b.getBundleId());
    }
}

Related

  1. loadColorTable(final File file)
  2. loadIntArrayFromFile(File file)
  3. readBytes(DataInputStream dataStream, int numberOfBytes)
  4. readBytes(DataInputStream input, int size)