Example usage for java.util NoSuchElementException toString

List of usage examples for java.util NoSuchElementException toString

Introduction

In this page you can find the example usage for java.util NoSuchElementException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.cloudera.oryx.als.serving.web.EstimateForAnonymousServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

    CharSequence pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
        return;//w w  w  .  j a va 2 s.  co m
    }
    Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
    String toItemID;
    Pair<String[], float[]> itemIDsAndValue;
    try {
        toItemID = pathComponents.next();
        itemIDsAndValue = RecommendToAnonymousServlet.parseItemValuePairs(pathComponents);
    } catch (NoSuchElementException nsee) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
        return;
    }

    if (itemIDsAndValue.getFirst().length == 0) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
        return;
    }

    String[] itemIDs = itemIDsAndValue.getFirst();
    unescapeSlashHack(itemIDs);
    float[] values = itemIDsAndValue.getSecond();

    OryxRecommender recommender = getRecommender();
    try {
        float estimate = recommender.estimateForAnonymous(toItemID, itemIDs, values);
        Writer out = response.getWriter();
        out.write(Float.toString(estimate));
        out.write('\n');
    } catch (NotReadyException nre) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
    } catch (NoSuchItemException nsie) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString());
    }
}

From source file:net.myrrix.web.servlets.EstimateForAnonymousServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

    CharSequence pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
        return;/*from w w  w.  j av a  2 s. co m*/
    }
    Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
    long toItemID;
    Pair<long[], float[]> itemIDsAndValue;
    try {
        toItemID = Long.parseLong(pathComponents.next());
        itemIDsAndValue = RecommendToAnonymousServlet.parseItemValuePairs(pathComponents);
    } catch (NoSuchElementException nsee) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
        return;
    } catch (NumberFormatException nfe) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString());
        return;
    }

    if (itemIDsAndValue.getFirst().length == 0) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
        return;
    }

    long[] itemIDs = itemIDsAndValue.getFirst();
    float[] values = itemIDsAndValue.getSecond();

    MyrrixRecommender recommender = getRecommender();
    try {
        float estimate = recommender.estimateForAnonymous(toItemID, itemIDs, values);
        Writer out = response.getWriter();
        out.write(Float.toString(estimate));
        out.write('\n');
    } catch (NotReadyException nre) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
    } catch (NoSuchItemException nsie) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString());
    } catch (TasteException te) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
        getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
    }
}

From source file:com.cloudera.oryx.als.serving.web.RecommendToAnonymousServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

    CharSequence pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
        return;/*from  w  ww.  ja  v a 2  s . c o m*/
    }
    Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
    Pair<String[], float[]> itemIDsAndValue;
    try {
        itemIDsAndValue = parseItemValuePairs(pathComponents);
    } catch (NoSuchElementException nsee) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
        return;
    }

    if (itemIDsAndValue.getFirst().length == 0) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
        return;
    }

    String[] itemIDs = itemIDsAndValue.getFirst();
    float[] values = itemIDsAndValue.getSecond();

    OryxRecommender recommender = getRecommender();
    RescorerProvider rescorerProvider = getRescorerProvider();
    try {
        Rescorer rescorer = rescorerProvider == null ? null
                : rescorerProvider.getRecommendToAnonymousRescorer(itemIDs, recommender,
                        getRescorerParams(request));
        output(response, recommender.recommendToAnonymous(itemIDs, values, getHowMany(request), rescorer));
    } catch (NotReadyException nre) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
    } catch (NoSuchItemException nsie) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString());
    } catch (IllegalArgumentException iae) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString());
    }
}

From source file:net.myrrix.web.servlets.RecommendToAnonymousServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

    CharSequence pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
        return;//from   w  ww .j a  v a  2 s.c  om
    }
    Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
    Pair<long[], float[]> itemIDsAndValue;
    try {
        itemIDsAndValue = parseItemValuePairs(pathComponents);
    } catch (NoSuchElementException nsee) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
        return;
    } catch (NumberFormatException nfe) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString());
        return;
    }

    if (itemIDsAndValue.getFirst().length == 0) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
        return;
    }

    long[] itemIDs = itemIDsAndValue.getFirst();
    float[] values = itemIDsAndValue.getSecond();

    MyrrixRecommender recommender = getRecommender();
    RescorerProvider rescorerProvider = getRescorerProvider();
    try {
        IDRescorer rescorer = rescorerProvider == null ? null
                : rescorerProvider.getRecommendToAnonymousRescorer(itemIDs, recommender,
                        getRescorerParams(request));
        Iterable<RecommendedItem> recommended = recommender.recommendToAnonymous(itemIDs, values,
                getHowMany(request), rescorer);
        output(request, response, recommended);
    } catch (NotReadyException nre) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
    } catch (NoSuchItemException nsie) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString());
    } catch (TasteException te) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
        getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
    } catch (IllegalArgumentException iae) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString());
    }
}

From source file:net.myrrix.web.servlets.IngestServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    MyrrixRecommender recommender = getRecommender();

    boolean fromBrowserUpload = request.getContentType().startsWith("multipart/form-data");

    Reader reader;/*from  w  w w . j av a2s  .  c  o m*/
    if (fromBrowserUpload) {

        Collection<Part> parts = request.getParts();
        if (parts == null || parts.isEmpty()) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No form data");
            return;
        }
        Part part = parts.iterator().next();
        String partContentType = part.getContentType();
        InputStream in = part.getInputStream();
        if ("application/zip".equals(partContentType)) {
            in = new ZipInputStream(in);
        } else if ("application/gzip".equals(partContentType)) {
            in = new GZIPInputStream(in);
        } else if ("application/x-gzip".equals(partContentType)) {
            in = new GZIPInputStream(in);
        } else if ("application/bzip2".equals(partContentType)) {
            in = new BZip2CompressorInputStream(in);
        } else if ("application/x-bzip2".equals(partContentType)) {
            in = new BZip2CompressorInputStream(in);
        }
        reader = new InputStreamReader(in, Charsets.UTF_8);

    } else {

        String charEncodingName = request.getCharacterEncoding();
        Charset charEncoding = charEncodingName == null ? Charsets.UTF_8 : Charset.forName(charEncodingName);
        String contentEncoding = request.getHeader(HttpHeaders.CONTENT_ENCODING);
        if (contentEncoding == null) {
            reader = request.getReader();
        } else if ("gzip".equals(contentEncoding)) {
            reader = new InputStreamReader(new GZIPInputStream(request.getInputStream()), charEncoding);
        } else if ("zip".equals(contentEncoding)) {
            reader = new InputStreamReader(new ZipInputStream(request.getInputStream()), charEncoding);
        } else if ("bzip2".equals(contentEncoding)) {
            reader = new InputStreamReader(new BZip2CompressorInputStream(request.getInputStream()),
                    charEncoding);
        } else {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unsupported Content-Encoding");
            return;
        }

    }

    try {
        recommender.ingest(reader);
    } catch (IllegalArgumentException iae) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString());
        return;
    } catch (NoSuchElementException nsee) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
        return;
    } catch (TasteException te) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
        getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
        return;
    }

    String referer = request.getHeader(HttpHeaders.REFERER);
    if (fromBrowserUpload && referer != null) {
        // Parsing avoids response splitting
        response.sendRedirect(new URL(referer).toString());
    }

}

From source file:com.couchbase.client.spring.cache.CouchbaseCacheTests.java

@Test
public void testClearingEmptyCacheUsingViewSucceeds() {
    CouchbaseCache cache = new CouchbaseCache("emptyCache", client);
    String unrelatedId = "unrelated";
    cache.getNativeCache().upsert(JsonDocument.create(unrelatedId, JsonObject.empty()));

    try {//  www.j ava2 s  . co  m
        cache.clear();
    } catch (NoSuchElementException e) {
        fail("Cache clearing failed on empty cache: " + e.toString());
    }
    assertTrue(cache.getNativeCache().exists(unrelatedId));
}

From source file:net.longfalcon.newsj.Backfill.java

/**
 * Returns single timestamp from a local article number
 * @param nntpClient/*from  w  w w . ja  va  2  s  .  com*/
 * @param articleNumber
 * @param debug
 * @return
 */
public DateTime postDate(NewsClient nntpClient, long articleNumber, boolean debug) throws IOException {
    int attempts = 0;
    boolean success = false;
    String dateString = "";
    do {
        try {
            Iterable<NewsArticle> articleIterable = nntpClient.iterateArticleInfo(articleNumber, articleNumber);
            NewsArticle article = articleIterable.iterator().next();
            if (article.getDate() != null) {
                dateString = article.getDate();
                success = true;
            } else {
                success = false;
            }
        } catch (NoSuchElementException e) {
            if (debug) {
                _log.debug(e.toString());
            }
            success = false;
        } catch (Exception e) {
            _log.error(e.toString(), e);
            success = false;
        }
        if (debug && attempts > 0) {
            _log.info(String.format("retried %d time(s)", attempts));
        }
        attempts++;

    } while (attempts <= 3 && !success);

    if (!success) {
        _log.warn("unable to find message id " + articleNumber);
        return null;
    }
    DateTime postDate = DateUtil.parseNNTPDate(dateString);
    return postDate;
}

From source file:forseti.JUtil.java

public static synchronized boolean INIT() {
    boolean init = false;
    // Inicializacion de propiedades de configuracion
    System.out.println("Iniciando JUtil y Configuracion de Sistema");
    m_TAREAS = new JFsiTareas();
    m_REINICIAR = false;//  ww  w.  j  a va  2s .  c o  m

    try {
        FileReader file = new FileReader("/usr/local/forseti/bin/.forseti_conf");
        BufferedReader buff = new BufferedReader(file);
        boolean eof = false;
        //masProp = new Properties();

        while (!eof) {
            String line = buff.readLine();
            if (line == null) {
                eof = true;
            } else {
                try {
                    StringTokenizer st = new StringTokenizer(line, "=");
                    String key = st.nextToken();
                    String value = st.nextToken();
                    if (key.equals("LANG"))
                        m_LANG = value;
                    if (key.equals("PASS"))
                        m_PASS = value;
                    else if (key.equals("ADDR"))
                        m_ADDR = value;
                    else if (key.equals("PORT"))
                        m_PORT = value;
                    else if (key.equals("INIT"))
                        init = (value.equals("true") ? true : false);
                } catch (NoSuchElementException e) {
                    continue;
                }
            }
        }
        buff.close();
        return init;
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e.toString());
    }
}

From source file:net.timewalker.ffmq4.remote.session.RemoteQueueBrowserEnumeration.java

@Override
public AbstractMessage nextElement() {
    if (endOfQueueReached)
        throw new NoSuchElementException();

    try {//w w  w.ja v  a 2s  . c o  m
        checkNotClosed();
        AbstractMessage msg = fetchNext();
        if (msg != null) {
            nextMessage = null; // Consume fetched message

            // Make sure the message is fully deserialized and marked as read-only
            msg.ensureDeserializationLevel(MessageSerializationLevel.FULL);
            msg.markAsReadOnly();

            return msg;
        }

        throw new NoSuchElementException();
    } catch (NoSuchElementException e) {
        throw e;
    } catch (JMSException e) {
        throw new IllegalStateException(e.toString());
    }
}