Package com.sun.enterprise.admin.common

Examples of com.sun.enterprise.admin.common.ByteChunk


        {
            String msg = localStrings.getString( "admin.mbeans.ssmb.call_preparedownload_first" );
            throw new MBeanException( new java.lang.IllegalStateException( msg ) );
        }
        // if it is a file of 0, return null bytes
        ByteChunk           byteChunk   = null;
        if (downloadInfo.downloadFile.length() == 0 ) {
            byte[] bytes = new byte[ByteChunk.kChunkMinSize];
            byteChunk = new ByteChunk(bytes,
                             downloadInfo.downloadFile.getAbsolutePath(),
                             true, true);
            unlockAndReset();
            return byteChunk;
        }

        if ((chunkIndex >= downloadInfo.numChunks) || (chunkIndex < 0))
        {
            String msg = localStrings.getString( "admin.mbeans.ssmb.invalid_chunk_index" );
            unlockAndReset();
            throw new MBeanException( new java.lang.IllegalStateException( msg ) );
        }
        RandomAccessFile    raf         = null;
        try
        {
            raf = new RandomAccessFile(downloadInfo.downloadFile, "r");
            byte[] bytes = new byte[ByteChunk.kChunkMaxSize];
            raf.seek(downloadInfo.numBytesRead);
            int actualBytesRead = raf.read(bytes, 0, ByteChunk.kChunkMaxSize);
            /*
            Debug.println("Read " + actualBytesRead + " from " +
                          downloadInfo.numBytesRead);
            */
            if (actualBytesRead < bytes.length)
            {
                byte[] newBytes = new byte[actualBytesRead];
                System.arraycopy(bytes, 0, newBytes, 0, newBytes.length);
                bytes = newBytes;
            }
            downloadInfo.numBytesRead += actualBytesRead;
            boolean isFirstChunk    = (chunkIndex == 0);
            boolean isLastChunk     =
                (chunkIndex == (downloadInfo.numChunks - 1));
            sLogger.log(Level.FINEST, "chunkIndex = " + chunkIndex +
                          " isFirstChunk = " + isFirstChunk +
                          " isLastChunk = " + isLastChunk);
            byteChunk = new ByteChunk(bytes,
                             downloadInfo.downloadFile.getAbsolutePath(),
                             isFirstChunk, isLastChunk);
        }
        catch (IOException ioe)
        {
            sLogger.log(Level.FINE, "mbean.download_failed", ioe);
            unlockAndReset();
            throw new MBeanException(ioe);
        }
        finally
        {
            if (raf != null)
            {
                try { raf.close(); }
                catch (IOException ioe) {}
            }
            if ((byteChunk != null) && (byteChunk.isLast()))
            {
                unlockAndReset();
            }
        }
        return byteChunk;
View Full Code Here


        // download file
        File targetFile = new File(info.getDownloadFilePath());

        // if it is a file of 0, return null bytes
        ByteChunk byteChunk  = null;
        if (targetFile.length() == 0)
        {
            byte[] bytes = new byte[ByteChunk.kChunkMinSize];
            String fPath = info.getDownloadFilePath();
            byteChunk = new ByteChunk(bytes, fPath, true, true, fPath, 0);
            info.setChunk(byteChunk);

            return info;
        }

        // verifies that chunk index is valid
        if ( (info.getChunkIndex() >= info.getNumberOfChunks())
                || (info.getChunkIndex() < 0) )
        {
            String msg = localStrings.getString(
                "admin.mbeans.ssmb.invalid_chunk_index" );
            throw new MBeanException(new java.lang.IllegalStateException(msg));
        }

        // reads the chunk into a byte chunk object
        RandomAccessFile raf = null;
        try
        {
            raf = new RandomAccessFile(targetFile, "r");
            byte[] bytes = new byte[ByteChunk.kChunkMaxSize];
            raf.seek(info.getNumberOfBytesSent());

            int actualBytesRead = raf.read(bytes, 0, ByteChunk.kChunkMaxSize);
            if (actualBytesRead < bytes.length)
            {
                byte[] newBytes = new byte[actualBytesRead];
                System.arraycopy(bytes, 0, newBytes, 0, newBytes.length);
                bytes = newBytes;
            }

            // increments the counter
            info.incrementNumberOfBytesSent(bytes.length);

            String path = info.getDownloadFilePath();
            byteChunk = new ByteChunk(bytes,
                             path, info.isFirstChunk(), info.isLastChunk(),
                             path, targetFile.length());
        }
        catch (IOException ioe)
        {
View Full Code Here

        {
      String msg = localStrings.getString( "admin.server.core.mbean.config.invalid_chunk_index" );
            throw new ControlException( msg );
    }
        RandomAccessFile    raf         = null;
        ByteChunk           byteChunk   = null;
        try
        {
            raf = new RandomAccessFile(downloadInfo.downloadFile, "r");
            byte[] bytes = new byte[ByteChunk.kChunkMaxSize];
            raf.seek(downloadInfo.numBytesRead);
            int actualBytesRead = raf.read(bytes, 0, ByteChunk.kChunkMaxSize);
            /*
            Debug.println("Read " + actualBytesRead + " from " +
                          downloadInfo.numBytesRead);
            */
            if (actualBytesRead < bytes.length)
            {
                byte[] newBytes = new byte[actualBytesRead];
                for (int i = 0; i < newBytes.length; i++)
                {
                    newBytes[i] = bytes[i];
                }
                bytes = newBytes;
            }
            downloadInfo.numBytesRead += actualBytesRead;
            boolean isFirstChunk    = (chunkIndex == 0);
            boolean isLastChunk     =
                (chunkIndex == (downloadInfo.numChunks - 1));
            sLogger.log(Level.FINEST, "chunkIndex = " + chunkIndex +
                          " isFirstChunk = " + isFirstChunk +
                          " isLastChunk = " + isLastChunk);
            byteChunk = new ByteChunk(bytes,
                             downloadInfo.downloadFile.getAbsolutePath(),
                             isFirstChunk, isLastChunk);
        }
        catch (Exception ioe)
        {
            sLogger.log(Level.FINE, "mbean.download_failed", ioe);
            downloadInfo.reset();
            try
            {
                lock.release();
            }
            catch (Exception e)
            {
                sLogger.log(Level.FINEST, "lock could not be released");
            }
            throw new ControlException(ioe.toString());
        }
        finally
        {
            if (raf != null)
            {
                try { raf.close(); }
                catch (IOException ioe) {}
            }
            if ((byteChunk != null) && (byteChunk.isLast()))
            {
                try
                {
                    downloadInfo.reset();
                    lock.release();
View Full Code Here

TOP

Related Classes of com.sun.enterprise.admin.common.ByteChunk

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.