int slashIndex = idString.lastIndexOf('/');  if (slashIndex != -1) { filename = idString.substring(slashIndex + 1); filename = URLDecoder.decode(filename, Constants.DEFAULT_ENCODING); handle = idString.substring(0, slashIndex); }    slashIndex = handle.indexOf('/'); slashIndex = handle.indexOf('/', slashIndex + 1);  if (slashIndex != -1) { handle = handle.substring(0, slashIndex); }   String relPath = null; slashIndex = idString.indexOf('/');
int slashIndex = idString.indexOf('/');
    protected void doDSGet(Context context, HttpServletRequest request,            HttpServletResponse response) throws ServletException, IOException,            SQLException, AuthorizeException    {        Bitstream bitstream = null;        // Get the ID from the URL        String idString = request.getPathInfo();        String filename = "";        String handle = "";        if (idString != null)        {            // Remove leading slash            if (idString.startsWith("/"))            {                idString = idString.substring(1);            }            // Get filename            int slashIndex = idString.lastIndexOf('/');            if (slashIndex != -1)            {                filename = idString.substring(slashIndex + 1);                filename = URLDecoder.decode(filename,                        Constants.DEFAULT_ENCODING);                handle = idString.substring(0, slashIndex);            }            // If there's still a second slash, remove it and anything after it,            // it might be a relative directory name            slashIndex = handle.indexOf('/');            slashIndex = handle.indexOf('/', slashIndex + 1);            if (slashIndex != -1)            {                handle = handle.substring(0, slashIndex);            }            /* Get entire relative path after handle, in case it             * is actually the bitstream name.  e.g. for item             * with handle 1234.56/13, the URL for an item could be:             * .../dspace/1234.56/13/sub1/sub2/foo.html             * so return relative path: "sub1/sub2/foo.html"             * Also translate any encoded slashes, etc. to match bitstream name.             */            String relPath = null;            slashIndex = idString.indexOf('/');            if (slashIndex != -1)            {                slashIndex = idString.indexOf('/', slashIndex + 1);                if (slashIndex != -1)                    relPath = URLDecoder.decode(idString.substring(slashIndex + 1),                                                Constants.DEFAULT_ENCODING);            }            // Find the corresponding bitstream            try            {                boolean found = false;                Item item = null;                /*                 * If the original item doesn't have a Handle yet (because it's                 * in the workflow) what we actually have is a fake Handle in                 * the form: db-id/1234 where 1234 is the database ID of the                 * item.                 */                if (handle.startsWith("db-id"))                {                    String dbIDString = handle                            .substring(handle.indexOf('/') + 1);                    int dbID = Integer.parseInt(dbIDString);                    item = Item.find(context, dbID);                }                else                {                    item = (Item) HandleManager                            .resolveToObject(context, handle);                }                if (item == null)                {                    log.info(LogManager.getHeader(context, "invalid_id",                            "path=" + handle));                    JSPManager                            .showInvalidIDError(request, response, handle, -1);                    return;                }                if (relPath == null ||                    (bitstream = getItemBitstreamByName(item, relPath)) == null)                    bitstream = getItemBitstreamByName(item, filename);            }            catch (NumberFormatException nfe)            {                // Invalid ID - this will be dealt with below            }        }        // Did we get a bitstream?        if (bitstream != null)        {            log.info(LogManager.getHeader(context, "view_bitstream",                    "bitstream_id=" + bitstream.getID()));            // Set the response MIME type            response.setContentType(bitstream.getFormat().getMIMEType());            // Response length            response.setHeader("Content-Length", String.valueOf(bitstream                    .getSize()));            // Pipe the bits            InputStream is = bitstream.retrieve();            Utils.bufferedCopy(is, response.getOutputStream());            is.close();            response.getOutputStream().flush();        }        else        {            // No bitstream - we got an invalid ID            log.info(LogManager.getHeader(context, "view_bitstream",                    "invalid_bitstream_id=" + idString));            JSPManager.showInvalidIDError(request, response, idString,                    Constants.BITSTREAM);        }    }