List of usage examples for java.lang StringIndexOutOfBoundsException StringIndexOutOfBoundsException
public StringIndexOutOfBoundsException()
From source file:org.omnaest.utils.strings.StringUtils.java
public static String insertString(String baseString, String insertString, int insertPosition, boolean overwrite) { ///*from w ww . j ava 2s . c om*/ String retval = null; // if (insertPosition < baseString.length()) { StringBuffer sb = new StringBuffer(baseString); for (int iInsertPosition = insertPosition; iInsertPosition < insertPosition + insertString.length() && iInsertPosition < baseString.length(); iInsertPosition++) { int insertStringSourcePosition = iInsertPosition - insertPosition; if (overwrite) { sb.deleteCharAt(iInsertPosition); } sb.insert(iInsertPosition, insertString.substring(insertStringSourcePosition, insertStringSourcePosition + 1)); } retval = sb.toString(); } else { throw new StringIndexOutOfBoundsException(); } // return retval; }
From source file:com.geecko.QuickLyric.lyrics.Genius.java
public static Lyrics fromURL(String url, String artist, String title) { Document lyricsPage;/*from w w w. ja va 2s. c om*/ String text; try { lyricsPage = Jsoup.connect(url).get(); Elements lyricsDiv = lyricsPage.select("div.lyrics"); if (lyricsDiv.isEmpty()) throw new StringIndexOutOfBoundsException(); else text = Jsoup.clean(lyricsDiv.html(), Whitelist.none().addTags("br")).trim(); } catch (HttpStatusException e) { return new Lyrics(Lyrics.NO_RESULT); } catch (IOException | StringIndexOutOfBoundsException e) { e.printStackTrace(); return new Lyrics(Lyrics.ERROR); } if (artist == null) { title = lyricsPage.getElementsByClass("text_title").get(0).text(); artist = lyricsPage.getElementsByClass("text_artist").get(0).text(); } Lyrics result = new Lyrics(Lyrics.POSITIVE_RESULT); if ("[Instrumental]".equals(text)) result = new Lyrics(Lyrics.NEGATIVE_RESULT); result.setArtist(artist); result.setTitle(title); result.setText(text); result.setURL(url); result.setSource("Genius"); return result; }
From source file:org.apache.gobblin.compaction.parser.CompactionPathParser.java
private void parseTimeAndDatasetName(FileSystemDataset dataset, CompactionParserResult rst) { String commonBase = rst.getSrcBaseDir(); String fullPath = dataset.datasetURN(); int startPos = fullPath.indexOf(commonBase) + commonBase.length(); String relative = StringUtils.removeStart(fullPath.substring(startPos), "/"); int delimiterStart = StringUtils.indexOf(relative, rst.getSrcSubDir()); if (delimiterStart == -1) { throw new StringIndexOutOfBoundsException(); }/*from w w w .ja v a2 s . c om*/ int delimiterEnd = relative.indexOf("/", delimiterStart); String datasetName = StringUtils.removeEnd(relative.substring(0, delimiterStart), "/"); String timeString = StringUtils.removeEnd(relative.substring(delimiterEnd + 1), "/"); rst.datasetName = datasetName; rst.timeString = timeString; rst.time = getTime(timeString); }
From source file:com.prgpascal.qrdatatransfer.TransferActivity.java
/** * Manipulate the incoming message.//w ww .j a v a 2s . com * The message can be a regular message or an ACK message. * If the Server receives an incorrect ACK, finish the Activity with an error. * If the Client receives an incorrect message, retry reading the same QR. * * @param message the incoming message. */ public void messageReceived(String message) { if (iAmTheServer) { // I'm the Server and a ACK has received (via Wifi Direct) if (message.equals(attendedAck)) { // The Ack is correct. // If available, next QR will be created by ServerAckReceiver. // Now, check if I've reached the EOT. if (isFinishingTransmission) { // EOT ack received, End of Transmission reached. // Finish the transmission with success. finishTransmissionWithSuccess(); } } else { // The Ack is incorrect (irreversible error). // Finish the Activity. finishTransmissionWithError(); } } else { // I'm the client and a message has received (via QR code scan) try { // Message received String ack = MyUtils.getAckFromMessage(message); String content = MyUtils.getContentFromMessage(message); String digest = MyUtils.getDigestFromMessage(message); // Check the digest if (digest.equals(MyUtils.calculateDigest(content))) { // Digest OK. // Check the content. if (content.startsWith(TAG_MAC)) { // MAC message, the First QR code of the transmission. // It contains the Server MAC address. // Start the connection with the Server. // DISABLE further QR codes scan, until connection is not established. makeQRscanAvailable(false); String mac = content.substring(TAG_MAC.length()); connect(mac); } else if (content.equals(TAG_EOT)) { // EOT message, End of Transmission reached // Send the last ACK message and finish the Activity with success. isFinishingTransmission = true; sendAck(ack); finishTransmissionWithSuccess(); } else { // Regular message, add it to the messages ArrayList messages.add(content); sendAck(ack); } } else { // Digest error. throw new StringIndexOutOfBoundsException(); } } catch (StringIndexOutOfBoundsException e) { // The message received is smaller than expected or error on digest. e.printStackTrace(); // Allow the QR to be read again clientFragment.resetPreviousMessage(); } } }