Example usage for org.apache.commons.lang3 StringUtils substringBetween

List of usage examples for org.apache.commons.lang3 StringUtils substringBetween

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringBetween.

Prototype

public static String substringBetween(final String str, final String open, final String close) 

Source Link

Document

Gets the String that is nested in between two Strings.

Usage

From source file:com.jelly.music.player.AsyncTasks.AsyncGetAlbumArtTask.java

@Override
protected Integer doInBackground(String... params) {
    /************************************************************************************************
     * RETRIEVE THE HTTP SEARCH RESPONSE FROM ITUNES SERVERS.
     ************************************************************************************************/

    //First, we'll make a HTTP request to iTunes' servers with the album and artist name.
    if (params.length == 2) {
        artist = params[0];//from   ww w . java 2  s  .  c  om
        album = params[1];

        //Create duplicate strings that will be filtered out for the URL.
        urlArtist = artist;
        urlAlbum = album;

        //Remove any unacceptable characters.
        if (urlArtist.contains("#")) {
            urlArtist = urlArtist.replace("#", "");
        }

        if (urlArtist.contains("$")) {
            urlArtist = urlArtist.replace("$", "");
        }

        if (urlArtist.contains("@")) {
            urlArtist = urlArtist.replace("@", "");
        }

        if (urlAlbum.contains("#")) {
            urlAlbum = urlAlbum.replace("#", "");
        }

        if (urlAlbum.contains("$")) {
            urlAlbum = urlAlbum.replace("$", "");
        }

        if (urlAlbum.contains("@")) {
            urlAlbum = urlAlbum.replace("@", "");
        }

        //Replace any spaces in the artist and album fields with "%20".
        if (urlArtist.contains(" ")) {
            urlArtist = urlArtist.replace(" ", "%20");
        }

        if (urlAlbum.contains(" ")) {
            urlAlbum = urlAlbum.replace(" ", "%20");
        }

    }

    //Construct the url for the HTTP request.
    URL uri = null;
    try {
        uri = new URL("http://itunes.apple.com/search?term=" + urlArtist + "+" + urlAlbum + "&entity=album");
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        return 1;
    }

    try {
        //Create a new HTTP connection.
        HttpURLConnection urlConnection = (HttpURLConnection) uri.openConnection();
        urlConnection.connect();

        //Set the destination directory for the xml file.
        File SDCardRoot = Environment.getExternalStorageDirectory();
        file = new File(SDCardRoot, "albumArt.xml");

        //Create the OuputStream that will be used to store the downloaded data into the file.
        FileOutputStream fileOutput = new FileOutputStream(file);

        //Create the InputStream that will read the data from the HTTP connection.
        InputStream inputStream = urlConnection.getInputStream();

        //Total size of target file.
        int totalSize = urlConnection.getContentLength();

        //Temp variable that stores the number of downloaded bytes.
        int downloadedSize = 0;

        //Create a buffer to store the downloaded bytes.
        byte[] buffer = new byte[1024];
        int bufferLength = 0;

        //Now read through the buffer and write the contents to the file.
        while ((bufferLength = inputStream.read(buffer)) > 0) {
            fileOutput.write(buffer, 0, bufferLength);
            downloadedSize += bufferLength;

        }

        //Close the File Output Stream.
        fileOutput.close();

    } catch (MalformedURLException e) {
        //TODO Auto-generated method stub
        e.printStackTrace();
        return 1;
    } catch (IOException e) {
        // TODO Auto-generated method stub
        e.printStackTrace();
        return 1;
    }

    //Create a File object that points to the downloaded file.
    File phpSource = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/albumArt.xml");
    String phpAsString = null;
    try {
        phpAsString = FileUtils.readFileToString(phpSource);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return 1;
    }

    //Extract the albumArt parameter from the PHP response.
    artworkURL = StringUtils.substringBetween(phpAsString, "\"artworkUrl100\":\"", "\",");
    if (artworkURL == null) {

        //Check and see if a lower resolution image available.
        artworkURL = StringUtils.substringBetween(phpAsString, "\"artworkUrl60\":\"", "\",");

        if (artworkURL == null) {
            URL_RETRIEVED = false;
            return 1;
        } else {
            //Replace "100x100" with "600x600" to retrieve larger album art images.
            artworkURL = artworkURL.replace("100x100", "600x600");
            URL_RETRIEVED = true;
        }

    } else {
        //Replace "100x100" with "600x600" to retrieve larger album art images.
        artworkURL = artworkURL.replace("100x100", "600x600");
        URL_RETRIEVED = true;
    }

    //Loop through the songs table and retrieve the data paths of all the songs (used to embed the artwork).

    //Replace any rogue apostrophes.
    if (album.contains("'")) {
        album = album.replace("'", "''");
    }

    if (artist.contains("'")) {
        artist = artist.replace("'", "''");
    }

    String selection = DBAccessHelper.SONG_ALBUM + "=" + "'" + album + "'" + " AND "
            + DBAccessHelper.SONG_ARTIST + "=" + "'" + artist + "'";

    String[] projection = { DBAccessHelper._ID, DBAccessHelper.SONG_FILE_PATH };

    Cursor cursor = mApp.getDBAccessHelper().getWritableDatabase().query(DBAccessHelper.MUSIC_LIBRARY_TABLE,
            projection, selection, null, null, null, null);

    if (cursor.getCount() != 0) {
        cursor.moveToFirst();
        dataURIsList.add(cursor.getString(1));

        while (cursor.moveToNext()) {
            dataURIsList.add(cursor.getString(1));
        }

    }

    cursor.close();

    if (URL_RETRIEVED == true) {
        artworkBitmap = mApp.getImageLoader().loadImageSync(artworkURL);

        File artworkFile = new File(Environment.getExternalStorageDirectory() + "/artwork.jpg");

        //Display the album art on the grid/listview so that the user knows that the download is complete.
        publishProgress();

        //Save the artwork.
        try {
            FileOutputStream out = new FileOutputStream(artworkFile);
            artworkBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            return 1;
        } finally {

            for (int i = 0; i < dataURIsList.size(); i++) {

                if (dataURIsList.get(i) != null) {

                    File audioFile = new File(dataURIsList.get(i));
                    AudioFile f = null;

                    try {
                        f = AudioFileIO.read(audioFile);
                    } catch (CannotReadException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (TagException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (ReadOnlyFileException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (InvalidAudioFrameException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    Tag tag = null;
                    try {
                        if (f != null) {
                            tag = f.getTag();
                        } else {
                            continue;
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                        continue;
                    }

                    Artwork artwork = null;
                    try {
                        artwork = ArtworkFactory.createArtworkFromFile(artworkFile);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        setArtworkAsFile(artworkFile, dataURIsList.get(i));
                        continue;
                    } catch (Error e) {
                        e.printStackTrace();
                        setArtworkAsFile(artworkFile, dataURIsList.get(i));
                        continue;
                    }

                    if (artwork != null) {

                        try {
                            tag.setField(artwork);
                        } catch (FieldDataInvalidException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            setArtworkAsFile(artworkFile, dataURIsList.get(i));
                            continue;
                        } catch (Exception e) {
                            e.printStackTrace();
                            setArtworkAsFile(artworkFile, dataURIsList.get(i));
                            continue;
                        } catch (Error e) {
                            e.printStackTrace();
                            setArtworkAsFile(artworkFile, dataURIsList.get(i));
                            continue;
                        }

                    }

                    try {
                        f.commit();
                    } catch (CannotWriteException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        setArtworkAsFile(artworkFile, dataURIsList.get(i));
                        continue;
                    } catch (Error e) {
                        e.printStackTrace();
                        setArtworkAsFile(artworkFile, dataURIsList.get(i));
                        continue;
                    }

                    //Update the album art tag in jelly' database.
                    ContentValues values = new ContentValues();
                    String filePath = dataURIsList.get(i);
                    filePath = filePath.replace("'", "''");
                    String where = DBAccessHelper.SONG_FILE_PATH + "=" + "'" + filePath + "'";
                    values.put(DBAccessHelper.SONG_ALBUM_ART_PATH, "byte://" + dataURIsList.get(i));

                    mApp.getDBAccessHelper().getWritableDatabase().update(DBAccessHelper.MUSIC_LIBRARY_TABLE,
                            values, where, null);

                } else {
                    continue;
                }

            }

            //Refresh the memory/disk cache for the ImageLoader instance.
            try {
                mApp.getImageLoader().clearMemoryCache();
                mApp.getImageLoader().clearDiscCache();
            } catch (Exception e) {
                e.printStackTrace();
            }

            //Delete the temporary files once the artwork has been embedded.
            artworkFile.delete();
            file.delete();

        }

    }

    return 0;
}

From source file:com.aniruddhc.acemusic.player.AsyncTasks.AsyncGetAlbumArtTask.java

@Override
protected Integer doInBackground(String... params) {
    /************************************************************************************************
     * RETRIEVE THE HTTP SEARCH RESPONSE FROM ITUNES SERVERS.
     ************************************************************************************************/

    //First, we'll make a HTTP request to iTunes' servers with the album and artist name.
    if (params.length == 2) {
        artist = params[0];//from  w  w w  .jav a 2 s . c  o  m
        album = params[1];

        //Create duplicate strings that will be filtered out for the URL.
        urlArtist = artist;
        urlAlbum = album;

        //Remove any unacceptable characters.
        if (urlArtist.contains("#")) {
            urlArtist = urlArtist.replace("#", "");
        }

        if (urlArtist.contains("$")) {
            urlArtist = urlArtist.replace("$", "");
        }

        if (urlArtist.contains("@")) {
            urlArtist = urlArtist.replace("@", "");
        }

        if (urlAlbum.contains("#")) {
            urlAlbum = urlAlbum.replace("#", "");
        }

        if (urlAlbum.contains("$")) {
            urlAlbum = urlAlbum.replace("$", "");
        }

        if (urlAlbum.contains("@")) {
            urlAlbum = urlAlbum.replace("@", "");
        }

        //Replace any spaces in the artist and album fields with "%20".
        if (urlArtist.contains(" ")) {
            urlArtist = urlArtist.replace(" ", "%20");
        }

        if (urlAlbum.contains(" ")) {
            urlAlbum = urlAlbum.replace(" ", "%20");
        }

    }

    //Construct the url for the HTTP request.
    URL uri = null;
    try {
        uri = new URL("http://itunes.apple.com/search?term=" + urlArtist + "+" + urlAlbum + "&entity=album");
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        return 1;
    }

    try {
        //Create a new HTTP connection.
        HttpURLConnection urlConnection = (HttpURLConnection) uri.openConnection();
        urlConnection.connect();

        //Set the destination directory for the xml file.
        File SDCardRoot = Environment.getExternalStorageDirectory();
        file = new File(SDCardRoot, "albumArt.xml");

        //Create the OuputStream that will be used to store the downloaded data into the file.
        FileOutputStream fileOutput = new FileOutputStream(file);

        //Create the InputStream that will read the data from the HTTP connection.
        InputStream inputStream = urlConnection.getInputStream();

        //Total size of target file.
        int totalSize = urlConnection.getContentLength();

        //Temp variable that stores the number of downloaded bytes.
        int downloadedSize = 0;

        //Create a buffer to store the downloaded bytes.
        byte[] buffer = new byte[1024];
        int bufferLength = 0;

        //Now read through the buffer and write the contents to the file.
        while ((bufferLength = inputStream.read(buffer)) > 0) {
            fileOutput.write(buffer, 0, bufferLength);
            downloadedSize += bufferLength;

        }

        //Close the File Output Stream.
        fileOutput.close();

    } catch (MalformedURLException e) {
        //TODO Auto-generated method stub
        e.printStackTrace();
        return 1;
    } catch (IOException e) {
        // TODO Auto-generated method stub
        e.printStackTrace();
        return 1;
    }

    //Create a File object that points to the downloaded file.
    File phpSource = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/albumArt.xml");
    String phpAsString = null;
    try {
        phpAsString = FileUtils.readFileToString(phpSource);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return 1;
    }

    //Extract the albumArt parameter from the PHP response.
    artworkURL = StringUtils.substringBetween(phpAsString, "\"artworkUrl100\":\"", "\",");
    if (artworkURL == null) {

        //Check and see if a lower resolution image available.
        artworkURL = StringUtils.substringBetween(phpAsString, "\"artworkUrl60\":\"", "\",");

        if (artworkURL == null) {
            URL_RETRIEVED = false;
            return 1;
        } else {
            //Replace "100x100" with "600x600" to retrieve larger album art images.
            artworkURL = artworkURL.replace("100x100", "600x600");
            URL_RETRIEVED = true;
        }

    } else {
        //Replace "100x100" with "600x600" to retrieve larger album art images.
        artworkURL = artworkURL.replace("100x100", "600x600");
        URL_RETRIEVED = true;
    }

    //Loop through the songs table and retrieve the data paths of all the songs (used to embed the artwork).

    //Replace any rogue apostrophes.
    if (album.contains("'")) {
        album = album.replace("'", "''");
    }

    if (artist.contains("'")) {
        artist = artist.replace("'", "''");
    }

    String selection = DBAccessHelper.SONG_ALBUM + "=" + "'" + album + "'" + " AND "
            + DBAccessHelper.SONG_ARTIST + "=" + "'" + artist + "'";

    String[] projection = { DBAccessHelper._ID, DBAccessHelper.SONG_FILE_PATH };

    Cursor cursor = mApp.getDBAccessHelper().getWritableDatabase().query(DBAccessHelper.MUSIC_LIBRARY_TABLE,
            projection, selection, null, null, null, null);

    if (cursor.getCount() != 0) {
        cursor.moveToFirst();
        dataURIsList.add(cursor.getString(1));

        while (cursor.moveToNext()) {
            dataURIsList.add(cursor.getString(1));
        }

    }

    cursor.close();

    if (URL_RETRIEVED == true) {
        artworkBitmap = mApp.getImageLoader().loadImageSync(artworkURL);

        File artworkFile = new File(Environment.getExternalStorageDirectory() + "/artwork.jpg");

        //Display the album art on the grid/listview so that the user knows that the download is complete.
        publishProgress();

        //Save the artwork.
        try {
            FileOutputStream out = new FileOutputStream(artworkFile);
            artworkBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            return 1;
        } finally {

            for (int i = 0; i < dataURIsList.size(); i++) {

                if (dataURIsList.get(i) != null) {

                    File audioFile = new File(dataURIsList.get(i));
                    AudioFile f = null;

                    try {
                        f = AudioFileIO.read(audioFile);
                    } catch (CannotReadException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (TagException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (ReadOnlyFileException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (InvalidAudioFrameException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    Tag tag = null;
                    try {
                        if (f != null) {
                            tag = f.getTag();
                        } else {
                            continue;
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                        continue;
                    }

                    Artwork artwork = null;
                    try {
                        artwork = ArtworkFactory.createArtworkFromFile(artworkFile);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        setArtworkAsFile(artworkFile, dataURIsList.get(i));
                        continue;
                    } catch (Error e) {
                        e.printStackTrace();
                        setArtworkAsFile(artworkFile, dataURIsList.get(i));
                        continue;
                    }

                    if (artwork != null) {

                        try {
                            tag.setField(artwork);
                        } catch (FieldDataInvalidException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            setArtworkAsFile(artworkFile, dataURIsList.get(i));
                            continue;
                        } catch (Exception e) {
                            e.printStackTrace();
                            setArtworkAsFile(artworkFile, dataURIsList.get(i));
                            continue;
                        } catch (Error e) {
                            e.printStackTrace();
                            setArtworkAsFile(artworkFile, dataURIsList.get(i));
                            continue;
                        }

                    }

                    try {
                        f.commit();
                    } catch (CannotWriteException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        setArtworkAsFile(artworkFile, dataURIsList.get(i));
                        continue;
                    } catch (Error e) {
                        e.printStackTrace();
                        setArtworkAsFile(artworkFile, dataURIsList.get(i));
                        continue;
                    }

                    //Update the album art tag in Jams' database.
                    ContentValues values = new ContentValues();
                    String filePath = dataURIsList.get(i);
                    filePath = filePath.replace("'", "''");
                    String where = DBAccessHelper.SONG_FILE_PATH + "=" + "'" + filePath + "'";
                    values.put(DBAccessHelper.SONG_ALBUM_ART_PATH, "byte://" + dataURIsList.get(i));

                    mApp.getDBAccessHelper().getWritableDatabase().update(DBAccessHelper.MUSIC_LIBRARY_TABLE,
                            values, where, null);

                } else {
                    continue;
                }

            }

            //Refresh the memory/disk cache for the ImageLoader instance.
            try {
                mApp.getImageLoader().clearMemoryCache();
                mApp.getImageLoader().clearDiscCache();
            } catch (Exception e) {
                e.printStackTrace();
            }

            //Delete the temporary files once the artwork has been embedded.
            artworkFile.delete();
            file.delete();

        }

    }

    return 0;
}

From source file:com.adobe.cq.wcm.core.components.internal.models.v2.ImageImpl.java

protected void buildAreas() {
    areas = new ArrayList<>();
    String mapProperty = properties.get(Image.PN_MAP, String.class);
    if (StringUtils.isNotEmpty(mapProperty)) {
        // Parse the image map areas as defined at {@code Image.PN_MAP}
        String[] mapAreas = StringUtils.split(mapProperty, "][");
        for (String area : mapAreas) {
            int coordinatesEndIndex = area.indexOf(")");
            if (coordinatesEndIndex < 0) {
                break;
            }//from w w w.  j  av  a2 s  .c  o  m
            String shapeAndCoords = StringUtils.substring(area, 0, coordinatesEndIndex + 1);
            String shape = StringUtils.substringBefore(shapeAndCoords, "(");
            String coordinates = StringUtils.substringBetween(shapeAndCoords, "(", ")");
            String remaining = StringUtils.substring(area, coordinatesEndIndex + 1);
            String[] remainingTokens = StringUtils.split(remaining, "|");
            if (StringUtils.isBlank(shape) || StringUtils.isBlank(coordinates)) {
                break;
            }
            if (remainingTokens.length > 0) {
                String href = StringUtils.removeAll(remainingTokens[0], "\"");
                if (StringUtils.isBlank(href)) {
                    break;
                }
                String target = remainingTokens.length > 1 ? StringUtils.removeAll(remainingTokens[1], "\"")
                        : "";
                String alt = remainingTokens.length > 2 ? StringUtils.removeAll(remainingTokens[2], "\"") : "";
                String relativeCoordinates = remainingTokens.length > 3 ? remainingTokens[3] : "";
                relativeCoordinates = StringUtils.substringBetween(relativeCoordinates, "(", ")");
                if (href.startsWith("/")) {
                    href = Utils.getURL(request, pageManager, href);
                }
                areas.add(new ImageAreaImpl(shape, coordinates, relativeCoordinates, href, target, alt));
            }
        }
    }
}

From source file:com.thruzero.common.core.infonode.builder.TokenStreamInfoNodeBuilder.java

protected InfoNodeElement initLeafNode(final String tokenStream, final String separator,
        final InfoNodeElement targetNode) {
    // TODO-p1(george) Rewrite this using RegEx
    String attributeStream = StringUtils.substringBetween(tokenStream, "[@", "]");
    String elementName;/*from   w w w  . j  a va 2 s .c o  m*/
    String elementValue;

    // handle the attributes
    if (StringUtils.isEmpty(attributeStream)) {
        elementName = StringUtils.trimToNull(StringUtils.substringBefore(tokenStream, "="));
        elementValue = StringUtils.trimToNull(StringUtils.substringAfter(tokenStream, "="));
    } else {
        StringTokenizer st1 = new StringTokenizer(attributeStream, separator);

        while (st1.hasMoreTokens()) {
            String attributeSpec = st1.nextToken();
            StringTokenizer st2 = new StringTokenizer(attributeSpec, "=");

            if (!st2.hasMoreTokens()) {
                throw new TokenStreamException(
                        "Malformed Token Stream (missing attribute name and value): " + tokenStream);
            }
            String attributeName = StringUtils.removeStart(st2.nextToken().trim(), "@");

            String attributeValue = null;
            if (st2.hasMoreTokens()) {
                attributeValue = trimQuotes(st2.nextToken().trim());
            }

            if (StringUtils.isEmpty(attributeValue)) {
                throw new TokenStreamException(
                        "Malformed Token Stream (missing attribute value): " + tokenStream);
            }

            targetNode.setAttribute(attributeName, attributeValue);
        }

        elementName = StringUtils.trimToNull(StringUtils.substringBefore(tokenStream, "["));
        elementValue = StringUtils.trimToNull(StringUtils.substringAfter(tokenStream, "]"));
    }

    // set the element name
    if (elementName == null) {
        throw new TokenStreamException("Malformed Token Stream (missing element name): " + tokenStream);
    }
    targetNode.setName(elementName);

    // set the element value
    if (elementValue != null) {
        elementValue = StringUtils.removeStart(elementValue, "=");
        targetNode.setText(elementValue);
    }

    return targetNode;
}

From source file:jodtemplate.template.expression.DefaultExpressionHandler.java

private static String getInlineListFullName(final String text) {
    return StringUtils.substringBetween(text, INLINE_LIST_ITEM_BEGIN.toString(),
            INLINE_LIST_ITEM_END.toString());
}

From source file:com.denimgroup.threadfix.importer.impl.upload.ClangChannelImporter.java

private String getNativeIdFromReport(String input) {
    String id;//w w w .  j a  va 2 s .co  m
    id = StringUtils.substringBetween(input, "report-", ".html");
    if (id == null)
        id = StringUtils.substringAfterLast(input, "/");
    if (id == null)
        id = input;
    if (id.length() > 50)
        id = id.substring(id.length() - 50);
    return id;
}

From source file:com.threewks.thundr.http.service.ning.HttpServiceNing.java

private void addBody(HttpRequestNing request, BoundRequestBuilder builder) {
    Object body = request.getBody();
    if (isMultipart(request)) {
        for (Map.Entry<String, Object> parameter : request.getParameters().entrySet()) {
            Object value = parameter.getValue();
            builder.addBodyPart(new StringPart(parameter.getKey(), getValueAs(value, String.class), "UTF-8"));
        }/*from   w w  w.  j  a  v a 2  s . co  m*/
        for (FileParameter fileParam : request.getFileParameters()) {
            Object partBody = fileParam.getBody();
            byte[] data = getValueAs(partBody, byte[].class);
            String contentType = StringUtils.substringBefore(fileParam.getContentType(), ";");
            String characterEncoding = StringUtils.substringBetween(fileParam.getContentType(), "charset=\"",
                    "\"");
            builder.addBodyPart(new ByteArrayPart(fileParam.getName(), fileParam.getName(), data, contentType,
                    characterEncoding));
        }
        builder.setHeader(Header.ContentType, ContentType.MultipartFormData.value());
    } else if (body != null) {
        builder.setBody(convertOutgoing(body));
    }
}

From source file:com.adobe.acs.commons.data.Spreadsheet.java

/**
 * Look for type hints in the name of a column to extract a usable type. Also look for array hints as well. <br>
 * Possible formats: /*from   w w w .ja  va2 s.c o m*/
 * <ul>
 * <li>column-name - A column named "column-name" </li>
 * <li>col@int - An integer column named "col" </li>
 * <li>col2@int[] - An integer array colum named "col2", assumes standard delimiter (,) </li>
 * <li>col3@string[] or col3@[] - A String array named "col3", assumes standard delimiter (,)</li>
 * <li>col4@string[||] - A string array where values are using a custom delimiter (||)</li>
 * </ul>
 * 
 * @param name
 * @return
 */
private Class detectTypeFromName(String name) {
    boolean isArray = false;
    Class detectedClass = String.class;
    if (name.contains("@")) {
        String typeStr = StringUtils.substringAfter(name, "@");
        if (name.endsWith("]")) {
            String colName = convertHeaderName(name);
            isArray = true;
            String delimiter = StringUtils.substringBetween(name, "[", "]");
            typeStr = StringUtils.substringBefore("[", delimiter);
            if (!StringUtils.isEmpty(delimiter)) {
                delimiters.put(colName, delimiter);
            }
        }
        detectedClass = getClassFromName(typeStr);
    }
    if (isArray) {
        return getArrayType(detectedClass);
    } else {
        return detectedClass;
    }
}

From source file:jodtemplate.template.expression.DefaultExpressionHandler.java

private String getExpressionBody(final String expression) {
    String expressionBody = StringUtils.substringBetween(expression, beginTag, endTag);
    expressionBody = StringUtils.trim(expressionBody);
    expressionBody = expressionBody.replaceAll("[?]", "\"");
    return expressionBody;
}

From source file:com.wso2.code.quality.matrices.ChangesFinder.java

/**
 * This method is used to save the line ranges being modified in a given file to a list and add that list to the root list of
 *
 * @param fileNames   Arraylist of files names that are being affected by the relevant commit
 * @param patchString Array list having the patch string value for each of the file being changed
 *//* w  ww .ja v  a2s  .  c  o m*/

public void saveRelaventEditLineNumbers(ArrayList<String> fileNames, ArrayList<String> patchString) {
    //filtering only the line ranges that are modified and saving to a string array

    // cannot ues parallel streams here as the order of the line changes must be preserved
    patchString.stream().map(patch -> StringUtils.substringsBetween(patch, "@@ ", " @@"))
            .forEach(lineChanges -> {
                //filtering the lines ranges that existed in the previous file, that exists in the new file and saving them in to the same array
                IntStream.range(0, lineChanges.length).forEach(j -> {
                    //@@ -22,7 +22,7 @@ => -22,7 +22,7 => 22,28/22,28
                    String tempString = lineChanges[j];
                    String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, "-",
                            " +"); // for taking the authors and commit hashes of the previous lines
                    String lineRangeInTheNewFileResultedFromModification = StringUtils
                            .substringAfter(tempString, "+"); // for taking the parent commit

                    int intialLineNoInOldFile = Integer
                            .parseInt(StringUtils.substringBefore(lineRangeInTheOldFileBeingModified, ","));
                    int tempEndLineNoInOldFile = Integer
                            .parseInt(StringUtils.substringAfter(lineRangeInTheOldFileBeingModified, ","));
                    int endLineNoOfOldFile;
                    if (intialLineNoInOldFile != 0) {
                        // to filterout the newly created files
                        endLineNoOfOldFile = intialLineNoInOldFile + (tempEndLineNoInOldFile - 1);
                    } else {
                        endLineNoOfOldFile = tempEndLineNoInOldFile;
                    }
                    int intialLineNoInNewFile = Integer.parseInt(
                            StringUtils.substringBefore(lineRangeInTheNewFileResultedFromModification, ","));
                    int tempEndLineNoInNewFile = Integer.parseInt(
                            StringUtils.substringAfter(lineRangeInTheNewFileResultedFromModification, ","));
                    int endLineNoOfNewFile = intialLineNoInNewFile + (tempEndLineNoInNewFile - 1);
                    // storing the line ranges that are being modified in the same array by replacing values
                    lineChanges[j] = intialLineNoInOldFile + "," + endLineNoOfOldFile + "/"
                            + intialLineNoInNewFile + "," + endLineNoOfNewFile;
                });
                ArrayList<String> tempArrayList = new ArrayList<>(Arrays.asList(lineChanges));
                //adding to the array list which keep track of the line ranges being changed
                lineRangesChanged.add(tempArrayList);
            });
    System.out.println("done saving file names and their relevant modification line ranges");
    System.out.println(fileNames);
    System.out.println(lineRangesChanged + "\n");
}