Package edu.sdsc.grid.io

Examples of edu.sdsc.grid.io.GeneralFile


    public static InputStream retrieve(Context context, int id)
            throws SQLException, IOException
    {
        TableRow bitstream = DatabaseManager.find(context, "bitstream", id);

    GeneralFile file = getFile(bitstream);

    return (file != null) ? FileFactory.newFileInputStream(file) : null;
    }
View Full Code Here


            for (Iterator<TableRow> iterator = storage.iterator(); iterator.hasNext();)
            {
                TableRow row = iterator.next();
                int bid = row.getIntColumn("bitstream_id");

        GeneralFile file = getFile(row);

                // Make sure entries which do not exist are removed
                if (file == null || !file.exists())
                {
                    log.debug("file is null");
                    if (deleteDbRecords)
                    {
                        log.debug("deleting record");
                        if (verbose)
                        {
                            System.out.println(" - Deleting bitstream information (ID: " + bid + ")");
                        }
                        bitstreamInfoDAO.deleteBitstreamInfoWithHistory(bid);
                        if (verbose)
                        {
                            System.out.println(" - Deleting bitstream record from database (ID: " + bid + ")");
                        }
                        DatabaseManager.delete(context, "Bitstream", bid);
                    }
                    continue;
                }

                // This is a small chance that this is a file which is
                // being stored -- get it next time.
                if (isRecent(file))
                {
                  log.debug("file is recent");
                    continue;
                }

                if (deleteDbRecords)
                {
                    log.debug("deleting db record");
                    if (verbose)
                    {
                        System.out.println(" - Deleting bitstream information (ID: " + bid + ")");
                    }
                    bitstreamInfoDAO.deleteBitstreamInfoWithHistory(bid);
                    if (verbose)
                    {
                        System.out.println(" - Deleting bitstream record from database (ID: " + bid + ")");
                    }
                    DatabaseManager.delete(context, "Bitstream", bid);
                }

        if (isRegisteredBitstream(row.getStringColumn("internal_id"))) {
            continue;      // do not delete registered bitstreams
        }


                // Since versioning allows for multiple bitstreams, check if the internal identifier isn't used on another place
                TableRow duplicateBitRow = DatabaseManager.querySingleTable(context, "Bitstream", "SELECT * FROM Bitstream WHERE internal_id = ? AND bitstream_id <> ?", row.getStringColumn("internal_id"), bid);
                if(duplicateBitRow == null)
                {
                    boolean success = file.delete();

                    String message = ("Deleted bitstream " + bid + " (file "
                                + file.getAbsolutePath() + ") with result "
                                + success);
                    if (log.isDebugEnabled())
                    {
                        log.debug(message);
                    }
View Full Code Here

        if (file == null )
        {
            return;
        }
    GeneralFile tmp = file;

        for (int i = 0; i < directoryLevels; i++)
        {

      GeneralFile directory = tmp.getParentFile();
      GeneralFile[] files = directory.listFiles();

            // Only delete empty directories
            if (files.length != 0)
            {
                break;
            }

            directory.delete();
            tmp = directory;
        }
    }
View Full Code Here

        if (storeNumber == -1)
        {
            storeNumber = 0;
        }

    GeneralFile assetstore = assetStores[storeNumber];

    // turn the internal_id into a file path relative to the assetstore
    // directory
    String sInternalId = bitstream.getStringColumn("internal_id");

    // there are 4 cases:
    // -conventional bitstream, conventional storage
    // -conventional bitstream, srb storage
    // -registered bitstream, conventional storage
    // -registered bitstream, srb storage
    // conventional bitstream - dspace ingested, dspace random name/path
    // registered bitstream - registered to dspace, any name/path
    String sIntermediatePath = null;
    if (isRegisteredBitstream(sInternalId)) {
      sInternalId = sInternalId.substring(REGISTERED_FLAG.length());
      sIntermediatePath = "";
    } else {
     
      // Sanity Check: If the internal ID contains a
      // pathname separator, it's probably an attempt to
      // make a path traversal attack, so ignore the path
      // prefix.  The internal-ID is supposed to be just a
      // filename, so this will not affect normal operation.
      if (sInternalId.indexOf(File.separator) != -1)
            {
                sInternalId = sInternalId.substring(sInternalId.lastIndexOf(File.separator) + 1);
            }
     
      sIntermediatePath = getIntermediatePath(sInternalId);
    }

    StringBuffer bufFilename = new StringBuffer();
    if (assetstore instanceof LocalFile) {
      bufFilename.append(assetstore.getCanonicalPath());
      bufFilename.append(File.separator);
      bufFilename.append(sIntermediatePath);
      bufFilename.append(sInternalId);
      if (log.isDebugEnabled()) {
        log.debug("Local filename for " + sInternalId + " is "
View Full Code Here

TOP

Related Classes of edu.sdsc.grid.io.GeneralFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.