Example usage for java.lang NullPointerException getLocalizedMessage

List of usage examples for java.lang NullPointerException getLocalizedMessage

Introduction

In this page you can find the example usage for java.lang NullPointerException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.teleca.jamendo.api.impl.JamendoGet2ApiImpl.java

@Override
public Album[] getPopularAlbumsWeek() throws JSONException, WSError {

    String jsonString = doGet("id+name+url+image+rating+artist_name/album/json/?n=20&order=ratingweek_desc");
    if (jsonString == null)
        return null;

    try {/*  w ww  .  j  a v a  2 s.  c o m*/
        JSONArray jsonArrayAlbums = new JSONArray(jsonString);
        return AlbumFunctions.getAlbums(jsonArrayAlbums);
    } catch (NullPointerException e) {
        e.printStackTrace();
        throw new JSONException(e.getLocalizedMessage());
    }
}

From source file:net.dian1.player.api.impl.JamendoGet2ApiImpl.java

@Override
public Music[] getTracksByTracksId(int[] id, String encoding) throws JSONException, WSError {
    if (id == null)
        return null;

    String id_query = Caller.createStringFromIds(id);
    try {//from  w  w  w .  jav  a 2  s  . com
        String jsonString = doGet("id+numalbum+name+duration+rating+url+stream/track/json/?streamencoding="
                + encoding + "&n=" + id.length + "&id=" + id_query);
        JSONArray jsonArrayTracks = new JSONArray(jsonString);
        return getTracks(jsonArrayTracks, false);
    } catch (NullPointerException e) {
        e.printStackTrace();
        throw new JSONException(e.getLocalizedMessage());
    }
}

From source file:com.teleca.jamendo.api.impl.JamendoGet2ApiImpl.java

@Override
public Track[] getTracksByTracksId(int[] id, String encoding) throws JSONException, WSError {
    if (id == null)
        return null;

    String id_query = Caller.createStringFromIds(id);
    try {/* ww w . j a  v  a  2 s  . co  m*/
        String jsonString = doGet("id+numalbum+name+duration+rating+url+stream/track/json/?streamencoding="
                + encoding + "&n=" + id.length + "&id=" + id_query);
        JSONArray jsonArrayTracks = new JSONArray(jsonString);
        return getTracks(jsonArrayTracks, false);
    } catch (NullPointerException e) {
        e.printStackTrace();
        throw new JSONException(e.getLocalizedMessage());
    }
}

From source file:net.dian1.player.api.impl.JamendoGet2ApiImpl.java

@Override
public Music[] getAlbumTracks(Album album, String encoding, int count, int page) throws JSONException, WSError {
    try {/*from   www . j  a  v  a2  s . c o m*/
        String pagination = "&n=all";
        if (count != 0 && page != 0) {
            pagination = "&n=" + count + "&pn=" + page;
        }
        String jsonString = doGet("numalbum+id+name+duration+rating+url+stream/track/json/?album_id="
                + album.getId() + "&streamencoding=" + encoding + pagination);
        JSONArray jsonArrayTracks = new JSONArray(jsonString);

        return getTracks(jsonArrayTracks, true);
    } catch (NullPointerException e) {
        e.printStackTrace();
        throw new JSONException(e.getLocalizedMessage());
    }
}

From source file:com.teleca.jamendo.api.impl.JamendoGet2ApiImpl.java

@Override
public Track[] getAlbumTracks(Album album, String encoding, int count, int page) throws JSONException, WSError {
    try {//from   ww w.  ja  v  a2s . co m
        String pagination = "&n=all";
        if (count != 0 && page != 0) {
            pagination = "&n=" + count + "&pn=" + page;
        }
        String jsonString = doGet("numalbum+id+name+duration+rating+url+stream/track/json/?album_id="
                + album.getId() + "&streamencoding=" + encoding + pagination);
        JSONArray jsonArrayTracks = new JSONArray(jsonString);

        return getTracks(jsonArrayTracks, true);
    } catch (NullPointerException e) {
        e.printStackTrace();
        throw new JSONException(e.getLocalizedMessage());
    }
}

From source file:com.teleca.jamendo.api.impl.JamendoGet2ApiImpl.java

@Override
public Album[] getAlbumsByTracksId(int[] id) throws JSONException, WSError {
    if (id == null)
        return null;

    String id_query = Caller.createStringFromIds(id);

    try {/*from  w  w w .  j  av  a  2s.c o  m*/
        String jsonString = doGet(
                "id+name+url+image+rating+artist_name/album/json/?n=" + id.length + "&track_id=" + id_query);
        JSONArray jsonArrayAlbums = new JSONArray(jsonString);
        return AlbumFunctions.getAlbums(jsonArrayAlbums);
    } catch (NullPointerException e) {
        e.printStackTrace();
        throw new JSONException(e.getLocalizedMessage());
    }
}

From source file:org.opentaps.notes.rest.locale.Messages.java

/**
 * Returns class initialized with resource bundle of the requested locale.<br>
 * First we check URL for embed locale identifier that equals to Locale valid string representation.<br>
 * Example of encoding locale with URL is: <code>/notes/note/fr_fr/noteID</code><br>
 * If not found we have to check <code>Accept-Language</code> header and select first available language
 * looking through the list in the natural order.   
 *///from  w  ww .  ja  v  a 2  s.  c  o m
public static Messages getInstance(Request request) {
    List<Locale> localeList = null;
    // get encoded locale
    String lang = (String) request.getAttributes().get("lang");
    if (!GenericValidator.isBlankOrNull(lang)) {
        try {
            Locale locale = new Locale(lang);
            localeList = Arrays.asList(locale);
        } catch (NullPointerException e) {
            //do nothing
        }
    }

    // get languages from Accept-Language
    if (localeList == null || localeList.size() == 0) {
        ClientInfo clientInfo = request.getClientInfo();
        List<Preference<Language>> preferences = clientInfo.getAcceptedLanguages();
        localeList = new ArrayList<Locale>(preferences.size());
        for (Preference<Language> pref : preferences) {
            localeList.add(new Locale(pref.getMetadata().toString()));
        }
    }

    // looking for the first available
    if (localeList != null && localeList.size() > 0) {
        ResourceBundle.clearCache();
        for (Locale locale : localeList) {
            try {
                String langCode = locale.toString().replaceAll("-", "_");
                ResourceBundle rb = ResourceBundle.getBundle(BUNDLE_NAME, locale);
                Locale rbLocale = rb.getLocale();
                if (rbLocale == null || GenericValidator.isBlankOrNull(rbLocale.toString())) {
                    rbLocale = Locale.getDefault();
                }
                if (langCode.equalsIgnoreCase(rbLocale.toString())) {
                    return new Messages(rb);
                } else {
                    continue;
                }
            } catch (MissingResourceException e) {
                Log.logWarning(e.getLocalizedMessage());
                continue;
            }
        }
    }

    return new Messages(ResourceBundle.getBundle(BUNDLE_NAME));
}

From source file:com.flexive.core.stream.BinaryDownloadProtocol.java

/**
 * {@inheritDoc}/*from w ww.  j  a  va  2s .c o m*/
 */
@Override
public DataPacket<BinaryDownloadPayload> processPacket(DataPacket<BinaryDownloadPayload> dataPacket)
        throws StreamException {
    if (dataPacket.isExpectResponse() && dataPacket.isExpectStream()) {
        String mimeType;
        int datasize;

        final BinaryDescriptor.PreviewSizes previewSize = BinaryDescriptor.PreviewSizes
                .fromSize(dataPacket.getPayload().getSize());
        try {
            con = Database.getNonTXDataSource(dataPacket.getPayload().getDivision()).getConnection();
            bin = loadBinaryDescriptor(dataPacket, previewSize);

            if (dataPacket.getPayload().isForceImage() && previewSize == BinaryDescriptor.PreviewSizes.ORIGINAL
                    && !bin.getMimeType().startsWith("image")) {
                // choose biggest preview size if an image is required, but the binary is no image
                bin = loadBinaryDescriptor(dataPacket, BinaryDescriptor.PreviewSizes.SCREENVIEW);
            }
        } catch (NullPointerException e) {
            //FX-782, loadBinaryDescriptor failed
            return new DataPacket<BinaryDownloadPayload>(new BinaryDownloadPayload(true, "ex.stream.notFound"),
                    false);
        } catch (FxNotFoundException e) {
            LOG.error("Failed to lookup content storage for division #" + dataPacket.getPayload().getDivision()
                    + ": " + e.getLocalizedMessage());
            return new DataPacket<BinaryDownloadPayload>(new BinaryDownloadPayload(true, "ex.stream.notFound"),
                    false);
        } catch (SQLException e) {
            throw new StreamException("Database connection error: " + e.getMessage(), e);
        }
        if (bin == null || !bin.isBinaryFound())
            return new DataPacket<BinaryDownloadPayload>(new BinaryDownloadPayload(true, "ex.stream.notFound"),
                    false);
        mimeType = bin.getMimeType();
        datasize = bin.getSize();
        _buffer = new byte[4096];
        if (!mimeType.startsWith("image")) {
            try {
                pre_read = bin.read(_buffer, 0, 100);
            } catch (IOException e) {
                //silently ignore
            }
            String tmp = FxMediaEngine.detectMimeType(_buffer);
            if (tmp.startsWith("image"))
                mimeType = tmp;
        } else
            pre_read = 0;
        return new DataPacket<BinaryDownloadPayload>(new BinaryDownloadPayload(mimeType, datasize), false);
    }
    return null;
}

From source file:com.xorcode.andtweet.net.ConnectionOAuth.java

/**
 * Universal method for several Timelines...
 * //from www  .j  a v a  2  s .c om
 * @param url URL predefined for this timeline
 * @param sinceId
 * @param maxId
 * @param limit
 * @param page
 * @return
 * @throws ConnectionException
 */
private JSONArray getTimeline(String url, long sinceId, long maxId, int limit, int page)
        throws ConnectionException {
    setSinceId(sinceId);
    setLimit(limit);

    boolean ok = false;
    JSONArray jArr = null;
    try {
        Uri sUri = Uri.parse(url);
        Uri.Builder builder = sUri.buildUpon();
        if (getSinceId() != 0) {
            builder.appendQueryParameter("since_id", String.valueOf(getSinceId()));
        } else if (maxId != 0) { // these are mutually exclusive
            builder.appendQueryParameter("max_id", String.valueOf(maxId));
        }
        if (getLimit() != 0) {
            builder.appendQueryParameter("count", String.valueOf(getLimit()));
        }
        if (page != 0) {
            builder.appendQueryParameter("page", String.valueOf(page));
        }
        HttpGet get = new HttpGet(builder.build().toString());
        mConsumer.sign(get);
        String response = mClient.execute(get, new BasicResponseHandler());
        jArr = new JSONArray(response);
        ok = (jArr != null);
    } catch (NullPointerException e) {
        // It looks like a bug in the library, but we have to catch it 
        Log.e(TAG, "NullPointerException was caught, URL='" + url + "'");
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
        throw new ConnectionException(e.getLocalizedMessage());
    }
    if (MyLog.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "getTimeline '" + url + "' " + (ok ? "OK, " + jArr.length() + " statuses" : "FAILED"));
    }
    return jArr;
}

From source file:it.geosolutions.geobatch.actions.xstream.XstreamAction.java

public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException {

    // the output
    final Queue<EventObject> ret = new LinkedList<EventObject>();
    listenerForwarder.started();//w w  w .  ja  va2  s. co  m
    while (events.size() > 0) {
        final EventObject event = events.remove();
        if (event == null) {
            final String message = "The passed event object is null";
            if (LOGGER.isWarnEnabled())
                LOGGER.warn(message);
            if (conf.isFailIgnored()) {
                continue;
            } else {
                final ActionException e = new ActionException(this, message);
                listenerForwarder.failed(e);
                throw e;
            }
        }

        if (event instanceof FileSystemEvent) {
            // generate an object
            final File sourceFile = File.class.cast(event.getSource());
            if (!sourceFile.exists() || !sourceFile.canRead()) {
                final String message = "XstreamAction.adapter(): The passed FileSystemEvent "
                        + "reference to a not readable or not existent file: " + sourceFile.getAbsolutePath();
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(message);
                if (conf.isFailIgnored()) {
                    continue;
                } else {
                    final ActionException e = new ActionException(this, message);
                    listenerForwarder.failed(e);
                    throw e;
                }
            }
            FileInputStream inputStream = null;
            try {
                inputStream = new FileInputStream(sourceFile);
                final Map<String, String> aliases = conf.getAlias();
                if (aliases != null && aliases.size() > 0) {
                    for (String alias : aliases.keySet()) {
                        final Class<?> clazz = Class.forName(aliases.get(alias));
                        xstream.alias(alias, clazz);
                    }
                }

                listenerForwarder.setTask("Converting file to a java object");

                // deserialize
                final Object res = xstream.fromXML(inputStream);
                // generate event
                final EventObject eo = new EventObject(res);
                // append to the output
                ret.add(eo);

            } catch (XStreamException e) {
                // the object cannot be deserialized
                if (LOGGER.isErrorEnabled())
                    LOGGER.error("The passed FileSystemEvent reference to a not deserializable file: "
                            + sourceFile.getAbsolutePath(), e);
                if (conf.isFailIgnored()) {
                    continue;
                } else {
                    listenerForwarder.failed(e);
                    throw new ActionException(this, e.getLocalizedMessage());
                }
            } catch (Throwable e) {
                // the object cannot be deserialized
                if (LOGGER.isErrorEnabled())
                    LOGGER.error("XstreamAction.adapter(): " + e.getLocalizedMessage(), e);
                if (conf.isFailIgnored()) {
                    continue;
                } else {
                    listenerForwarder.failed(e);
                    throw new ActionException(this, e.getLocalizedMessage());
                }
            } finally {
                IOUtils.closeQuietly(inputStream);
            }

        } else {

            // try to serialize
            // build the output absolute file name
            File outputDir;
            try {
                outputDir = new File(conf.getOutput());
                // the output
                if (!outputDir.isAbsolute())
                    outputDir = it.geosolutions.tools.commons.file.Path.findLocation(outputDir, getTempDir());

                if (!outputDir.exists()) {
                    if (!outputDir.mkdirs()) {
                        final String message = "Unable to create the ouptut dir named: " + outputDir.toString();
                        if (LOGGER.isInfoEnabled())
                            LOGGER.info(message);
                        if (conf.isFailIgnored()) {
                            continue;
                        } else {
                            final ActionException e = new ActionException(this, message);
                            listenerForwarder.failed(e);
                            throw e;
                        }
                    }
                }
                if (LOGGER.isInfoEnabled()) {
                    LOGGER.info("Output dir name: " + outputDir.toString());
                }

            } catch (NullPointerException npe) {
                final String message = "Unable to get the output file path from :" + conf.getOutput();
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(message, npe);
                if (conf.isFailIgnored()) {
                    continue;
                } else {
                    listenerForwarder.failed(npe);
                    throw new ActionException(this, npe.getLocalizedMessage());
                }
            }

            final File outputFile;
            try {
                outputFile = File.createTempFile(conf.getOutput(), null, outputDir);
            } catch (IOException ioe) {
                final String message = "Unable to build the output file writer: " + ioe.getLocalizedMessage();
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(message, ioe);
                if (conf.isFailIgnored()) {
                    continue;
                } else {
                    listenerForwarder.failed(ioe);
                    throw new ActionException(this, ioe.getLocalizedMessage());
                }
            }

            // try to open the file to write into
            FileWriter fw = null;
            try {
                listenerForwarder.setTask("Serializing java object to " + outputFile);
                fw = new FileWriter(outputFile);

                final Map<String, String> aliases = conf.getAlias();
                if (aliases != null && aliases.size() > 0) {
                    for (String alias : aliases.keySet()) {
                        final Class<?> clazz = Class.forName(aliases.get(alias));
                        xstream.alias(alias, clazz);
                    }
                }
                xstream.toXML(event.getSource(), fw);

            } catch (XStreamException e) {
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(
                            "The passed event object cannot be serialized to: " + outputFile.getAbsolutePath(),
                            e);
                if (conf.isFailIgnored()) {
                    continue;
                } else {
                    listenerForwarder.failed(e);
                    throw new ActionException(this, e.getLocalizedMessage());
                }
            } catch (Throwable e) {
                // the object cannot be deserialized
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(e.getLocalizedMessage(), e);
                if (conf.isFailIgnored()) {
                    continue;
                } else {
                    listenerForwarder.failed(e);
                    throw new ActionException(this, e.getLocalizedMessage());
                }
            } finally {
                IOUtils.closeQuietly(fw);
            }

            // add the file to the queue
            ret.add(new FileSystemEvent(outputFile.getAbsoluteFile(), FileSystemEventType.FILE_ADDED));

        }
    }
    listenerForwarder.completed();
    return ret;
}