Example usage for java.lang IllegalArgumentException toString

List of usage examples for java.lang IllegalArgumentException toString

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.varoid.exoplanethunter.JSONParser.java

public void readJSONFeed(String URL) throws Exception {
    this.ret = "ff";
    StringBuilder stringBuilder = new StringBuilder();
    HttpClient httpClient = new DefaultHttpClient();
    this.ret = "wdsffdfdg";

    try {/*from w w  w . j a va 2  s . c  om*/

        httpGet = new HttpGet(URL);
    } catch (IllegalArgumentException e) {

        this.ret = "ucvt589hygf " + e.toString() + e.getMessage();
    }
    this.ret = "wdsfsdedg";
    try {
        HttpResponse response = httpClient.execute(httpGet);

        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            this.ret = "wedfgdfgg";
            HttpEntity entity = response.getEntity();
            InputStream inputStream = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String line;
            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line);
            }
            inputStream.close();
        } else {
            this.ret = "Failed to download file";
        }
    } catch (Exception e) {
        this.ret = "readJSONFeed" + e.toString();
    }
    this.ret = stringBuilder.toString();
}

From source file:com.offbynull.voip.audio.gateways.io.OutputWriteRunnable.java

@Override
public void run() {
    LOG.info("Output thread started: {}", openOutputDevice);
    try {/*from  w  w w .  ja va 2  s.  c o m*/
        byte[] internalBuffer = new byte[bufferSize];

        while (true) {
            LinkedList<OutputData> readBuffers = dumpQueue();
            Iterator<OutputData> readBuffersIt = readBuffers.descendingIterator();
            int remainingAmount = internalBuffer.length;
            int requiredAmount = 0;
            int copyAmount = 0;
            while (remainingAmount > 0 && readBuffersIt.hasNext()) {
                OutputData readBuffer = readBuffersIt.next();
                byte[] readBufferData = readBuffer.getData();
                requiredAmount = readBufferData.length;

                copyAmount = Math.min(remainingAmount, requiredAmount);
                int copyFrom = requiredAmount - copyAmount;
                int copyTo = remainingAmount - copyAmount;

                System.arraycopy(readBufferData, copyFrom, internalBuffer, copyTo, copyAmount);

                remainingAmount -= copyAmount;
            }

            if (copyAmount != requiredAmount || readBuffersIt.hasNext()) { // more than 1 buffer or some data not copied, show a warning
                LOG.info("Excess data read: {} buffers -- only playing last {} bytes", readBuffers.size(),
                        bufferSize);
            }

            try {
                openOutputDevice.write(internalBuffer, remainingAmount,
                        internalBuffer.length - remainingAmount);
            } catch (IllegalArgumentException iae) {
                LOG.warn("Output buffer potentially malformed: {}", iae.toString());
            }
        }
    } catch (Exception e) {
        LOG.info("Output thread stopped: {}", e.toString());
    }
}

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.SpringApiClientImplTest.java

/**
 * Tests constructor {@link SpringApiClientImpl#SpringApiClientImpl(String, String, Integer, RestTemplate)} in the
 * case where the supplied protocol is invalid, because it's an unknown string.
 *///  www  .ja va  2 s.  c o m
@Test
public final void testConstructInvalidProtocolUnknown() {
    final String protocol = "foo";
    try {
        new SpringApiClientImpl(protocol, "api.test.brighttalk.net", 80, new RestTemplate());
        fail("Expected an exception to be thrown.");
    } catch (IllegalArgumentException e) {
        assertTrue("Unexepected exception message [" + e.toString() + "].",
                e.getMessage().matches(".*protocol.*" + protocol + ".*"));
    }
}

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.SpringApiClientImplTest.java

/**
 * Tests constructor {@link SpringApiClientImpl#SpringApiClientImpl(String, String, Integer, RestTemplate)} in the
 * case where the supplied port is invalid, because it's a negative number.
 *//*w w  w  . j a v  a2  s.c o m*/
@Test
public final void testConstructInvalidPortNegative() {
    int port = -1;
    try {
        new SpringApiClientImpl("https", "api.test.brighttalk.net", port, new RestTemplate());
        fail("Expected an exception to be thrown.");
    } catch (IllegalArgumentException e) {
        assertTrue("Unexepected exception message [" + e.toString() + "].",
                e.getMessage().matches(".*port.*" + port + ".*"));
    }
}

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.SpringApiClientImplTest.java

/**
 * Tests constructor {@link SpringApiClientImpl#SpringApiClientImpl(String, RestTemplate)} in the case where the
 * supplied host name is invalid, because it contains an unsupported character e.g a space.
 *//*  w ww. j  a v a2  s .  c om*/
@Test
public final void testConstructInvalidHostNameUnsupportedCharacter() {
    final String hostName = "<invalid host name>";
    try {
        new SpringApiClientImpl(hostName, new RestTemplate());
        fail("Expected an exception to be thrown.");
    } catch (IllegalArgumentException e) {
        assertTrue("Unexepected exception message [" + e.toString() + "].",
                e.getMessage().matches(".*host name.*" + hostName + ".*"));
    }
}

From source file:ca.mcgill.cs.creco.logic.AttributeExtractor.java

/** Constructor that takes a category.
 * @param pDataStore the whole space of interesting products
 *//*from w  w w .ja v  a  2s  .c o  m*/
@Autowired
public AttributeExtractor(IDataStore pDataStore) {
    aDataStore = pDataStore;
    aAllAttributes = new HashMap<String, ArrayList<ScoredAttribute>>();
    for (Category cat : aDataStore.getCategories()) {
        ArrayList<ScoredAttribute> scoredAttributeList = new ArrayList<ScoredAttribute>();
        HashMap<String, Attribute> attributes = new HashMap<String, Attribute>();
        for (Product prod : cat.getProducts()) {
            for (Attribute att : prod.getAttributes()) {
                attributes.put(att.getId(), att);
            }
        }
        for (String key : attributes.keySet()) {
            ScoredAttribute sa = null;
            try {
                sa = new ScoredAttribute(attributes.get(key), cat);
                sa.getAttributeID();
            } catch (IllegalArgumentException iae) {
                LOG.error(iae.toString());
            }

            scoredAttributeList.add(sa);
        }
        sort(DEFAULT_SORT, scoredAttributeList);
        aAllAttributes.put(cat.getId(), scoredAttributeList);

    }

}

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  w  w  .  j av a2s.  com
    }
    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;/*  ww  w . ja v a 2 s. c  o  m*/
    }
    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  www . j av  a 2s .com
    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:org.eurekastreams.commons.scheduling.TransactionalTaskRunner.java

/**
 * this method creates a transactional environment for calling mapper methods.
 *///from w  w w  . jav a2 s. c  o m
@Transactional
public void runTransactionalTask() {
    Date start = new Date();
    try {
        long startTime = start.getTime();
        method.invoke(target);
        Date end = new Date();
        long endTime = end.getTime();
        String message = "Method " + method.getName() + " started at " + start + " and finished at " + end
                + " taking " + ((endTime - startTime)) / MILLIS_TO_SECONDS + " seconds";
        log.info(message);
    } catch (IllegalArgumentException e) {
        String message = "Method " + method.getName() + " started at " + start;
        log.error(message);
        log.error(e.toString());
    } catch (IllegalAccessException e) {
        String message = "Method " + method.getName() + " started at " + start;
        log.error(message);
        log.error(e.toString());
    } catch (InvocationTargetException e) {
        String message = "Method " + method.getName() + " started at " + start;
        log.error(message);
        log.error(e.toString());
    }

}