Package net.easymodo.asagi.exception

Examples of net.easymodo.asagi.exception.ContentStoreException


            try {
                conn.rollback();
            } catch(SQLException e1) {
                e1.setNextException(e);
                throw new ContentStoreException(e1);
            }
            throw new ContentStoreException(e);
        }}
    }
View Full Code Here


        } catch(SQLException e) {
            try {
                conn.rollback();
            } catch(SQLException e1) {
                e1.setNextException(e);
                throw new ContentStoreException(e1);
            }
            throw new ContentStoreException(e);
        } }
    }
View Full Code Here

                try {
                    conn.rollback();
                } catch(SQLException e1) {
                    e.setNextException(e1);
                }
                throw new ContentStoreException(e);
            }
        }

        return media;
    }
View Full Code Here

        File tempDirFile = new File(tempDir);

        synchronized(this) {
            if(!subDir2File.exists())
                if(!subDir2File.mkdirs())
                    throw new ContentStoreException("Could not create dirs at path " + subDir2);

            if(!tempDirFile.exists())
                if(!tempDirFile.mkdirs())
                    throw new ContentStoreException("Could not create temp dir at path " + tempDir);

            if(this.webGroupId != 0) {
                posix.chmod(subDir, 0775);
                posix.chmod(subDir2, 0775);
                posix.chown(subDir, -1, this.webGroupId);
View Full Code Here

    public void markDeleted(DeletedPost post) throws ContentStoreException {
        try{
            this.db.markDeleted(post);
        } catch(DBConnectionException e) {
            throw new ContentStoreException("Lost connection to database, can't reconnect", e);
        }
    }
View Full Code Here

        Media mediaRow;
        try {
            mediaRow = db.getMedia(h);
        } catch(DBConnectionException e) {
            throw new ContentStoreException("Lost connection to database, can't reconnect", e);
        }

        // Media is banned from archiving
        if(mediaRow.getBanned() == 1) return;

        // Get the proper filename for the file type we're outputting
        String filename;
        if(this.useOldDirectoryStructure)
            filename = isPreview ? h.getPreview() : h.getMedia();
        else
            filename = isPreview ? (h.isOp() ?  mediaRow.getPreviewOp() : mediaRow.getPreviewReply()) :
                mediaRow.getMedia();

        if(filename == null) return;

        // Create the dir structure (if necessary) and return the path to where we're outputting our file
        // Filename is enough for us here, we just need the first part of the string
        String outputDir;
        if(this.useOldDirectoryStructure)
            outputDir = makeDir(h, isPreview ? DIR_THUMB : DIR_MEDIA, FULL_FILE);
        else
            outputDir = makeDir(filename, isPreview ? DIR_THUMB : DIR_MEDIA, FULL_FILE);

        // Construct the path and back down if the file already exists
        File outputFile = new File(outputDir + "/" + filename);
        if(outputFile.exists()) {
            if (!isPreview) outputFile.setLastModified(System.currentTimeMillis());
            return;
        }

        // Open a temp file for writing
        String tempFilePath;
        if(this.useOldDirectoryStructure)
            tempFilePath = makeDir(h, isPreview ? DIR_THUMB : DIR_MEDIA, TEMP_FILE);
        else
            tempFilePath = makeDir(filename, isPreview ? DIR_THUMB : DIR_MEDIA, TEMP_FILE);


        // Throws ContentGetException on failure
        InputStream inStream = isPreview ? source.getMediaPreview(h) : source.getMedia(h);

        OutputStream outFile = null;
        File tempFile = null;
        try {
             tempFile = File.createTempFile(filename + "_", null, new File(tempFilePath + "/"));

            outFile = new BufferedOutputStream(new FileOutputStream(tempFile));

            // Copy the network input stream to our local file
            // In case the connection is cut off or something similar happens, an IOException
            // will be thrown.
            ByteStreams.copy(inStream, outFile);
        } catch(FileNotFoundException e) {
            throw new ContentStoreException("The temp file we just created wasn't there!", e);
        } catch(IOException e) {
            if(tempFile != null && !tempFile.delete())
                System.err.println("Additionally, temporary file " + tempFilePath + "/" + filename + " could not be deleted.");
                e.printStackTrace();
            throw new ContentStoreException("IOException in file download", e);
        } finally {
            try {
                if(outFile != null) outFile.close();
                inStream.close();
            } catch(IOException e) {
                System.err.println("IOException trying to close streams after file download");
                e.printStackTrace();
            }
        }

        // Move the temporary file into place
        if(!tempFile.renameTo(outputFile))
            throw new ContentStoreException("Unable to move temporary file " + tempFilePath + "/" + filename + " into place");

        try {
            if(this.webGroupId != 0) {
                posix.chmod(outputFile.getCanonicalPath(), 0664);
                posix.chown(outputFile.getCanonicalPath(), -1, this.webGroupId);
            }
        } catch(IOException e) {
            throw new ContentStoreException("IOException trying to get filename for output file (nice broken filesystem you have there)", e);
        }
    }
View Full Code Here

TOP

Related Classes of net.easymodo.asagi.exception.ContentStoreException

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.