⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitstream.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Bitstream.java * * Version: $Revision: 1.21 $ * * Date: $Date: 2005/11/17 19:02:04 $ * * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts * Institute of Technology.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of the Hewlett-Packard Company nor the name of the * Massachusetts Institute of Technology nor the names of their * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */package org.dspace.content;import java.io.IOException;import java.io.InputStream;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import org.apache.log4j.Logger;import org.dspace.authorize.AuthorizeException;import org.dspace.authorize.AuthorizeManager;import org.dspace.core.ConfigurationManager;import org.dspace.core.Constants;import org.dspace.core.Context;import org.dspace.core.LogManager;import org.dspace.storage.bitstore.BitstreamStorageManager;import org.dspace.storage.rdbms.DatabaseManager;import org.dspace.storage.rdbms.TableRow;import org.dspace.storage.rdbms.TableRowIterator;/** * Class representing bitstreams stored in the DSpace system. * <P> * When modifying the bitstream metadata, changes are not reflected in the * database until <code>update</code> is called. Note that you cannot alter * the contents of a bitstream; you need to create a new bitstream. *  * @author Robert Tansley * @version $Revision: 1.21 $ */public class Bitstream extends DSpaceObject{    /** log4j logger */    private static Logger log = Logger.getLogger(Bitstream.class);    /** Our context */    private Context bContext;    /** The row in the table representing this bitstream */    private TableRow bRow;    /** The bitstream format corresponding to this bitstream */    private BitstreamFormat bitstreamFormat;    /**     * Private constructor for creating a Bitstream object based on the contents     * of a DB table row.     *      * @param context     *            the context this object exists in     * @param row     *            the corresponding row in the table     * @throws SQLException     */    Bitstream(Context context, TableRow row) throws SQLException    {        bContext = context;        bRow = row;        // Get the bitstream format        bitstreamFormat = BitstreamFormat.find(context, row                .getIntColumn("bitstream_format_id"));        if (bitstreamFormat == null)        {            // No format: use "Unknown"            bitstreamFormat = BitstreamFormat.findUnknown(context);            // Panic if we can't find it            if (bitstreamFormat == null)            {                throw new IllegalStateException("No Unknown bitsream format");            }        }        // Cache ourselves        context.cache(this, row.getIntColumn("bitstream_id"));    }    /**     * Get a bitstream from the database. The bitstream metadata is loaded into     * memory.     *      * @param context     *            DSpace context object     * @param id     *            ID of the bitstream     *      * @return the bitstream, or null if the ID is invalid.     * @throws SQLException     */    public static Bitstream find(Context context, int id) throws SQLException    {        // First check the cache        Bitstream fromCache = (Bitstream) context                .fromCache(Bitstream.class, id);        if (fromCache != null)        {            return fromCache;        }        TableRow row = DatabaseManager.find(context, "bitstream", id);        if (row == null)        {            if (log.isDebugEnabled())            {                log.debug(LogManager.getHeader(context, "find_bitstream",                        "not_found,bitstream_id=" + id));            }            return null;        }        // not null, return Bitstream        if (log.isDebugEnabled())        {            log.debug(LogManager.getHeader(context, "find_bitstream",                    "bitstream_id=" + id));        }        return new Bitstream(context, row);    }    /**     * Create a new bitstream, with a new ID. The checksum and file size are     * calculated. This method is not public, and does not check authorisation;     * other methods such as Bundle.createBitstream() will check authorisation.     * The newly created bitstream has the "unknown" format.     *      * @param context     *            DSpace context object     * @param is     *            the bits to put in the bitstream     *      * @return the newly created bitstream     * @throws IOException     * @throws SQLException     */    static Bitstream create(Context context, InputStream is)            throws IOException, SQLException    {        // Store the bits        int bitstreamID = BitstreamStorageManager.store(context, is);        log.info(LogManager.getHeader(context, "create_bitstream",                "bitstream_id=" + bitstreamID));        // Set the format to "unknown"        Bitstream bitstream = find(context, bitstreamID);        bitstream.setFormat(null);        return bitstream;    }    /**     * Register a new bitstream, with a new ID.  The checksum and file size     * are calculated.  This method is not public, and does not check     * authorisation; other methods such as Bundle.createBitstream() will     * check authorisation.  The newly created bitstream has the "unknown"     * format.     *     * @param  context DSpace context object     * @param assetstore corresponds to an assetstore in dspace.cfg     * @param bitstreamPath the path and filename relative to the assetstore      * @return  the newly registered bitstream     * @throws IOException     * @throws SQLException     */    static Bitstream register(Context context,     		int assetstore, String bitstreamPath)        	throws IOException, SQLException    {        // Store the bits        int bitstreamID = BitstreamStorageManager.register(        		context, assetstore, bitstreamPath);        log.info(LogManager.getHeader(context,            "create_bitstream",            "bitstream_id=" + bitstreamID));        // Set the format to "unknown"        Bitstream bitstream = find(context, bitstreamID);        bitstream.setFormat(null);        return bitstream;    }    /**     * Get the internal identifier of this bitstream     *      * @return the internal identifier     */    public int getID()    {        return bRow.getIntColumn("bitstream_id");    }    public String getHandle()    {        // No Handles for bitstreams        return null;    }    /**     * Get the sequence ID of this bitstream     *      * @return the sequence ID     */    public int getSequenceID()    {        return bRow.getIntColumn("sequence_id");    }    /**     * Set the sequence ID of this bitstream     *      * @param sid     *            the ID     */    public void setSequenceID(int sid)    {        bRow.setColumn("sequence_id", sid);    }    /**     * Get the name of this bitstream - typically the filename, without any path     * information     *      * @return the name of the bitstream     */    public String getName()    {        return bRow.getStringColumn("name");    }    /**     * Set the name of the bitstream     *      * @param n     *            the new name of the bitstream     */    public void setName(String n)    {        bRow.setColumn("name", n);    }    /**     * Get the source of this bitstream - typically the filename with path     * information (if originally provided) or the name of the tool that     * generated this bitstream     *      * @return the source of the bitstream     */    public String getSource()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -