Search in sources :

Example 1 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project elasticsearch by elastic.

the class TestAmazonS3 method hashCode.

private int hashCode(String path) {
    try {
        MessageDigest digest = MessageDigest.getInstance("MD5");
        byte[] bytes = digest.digest(path.getBytes("UTF-8"));
        int i = 0;
        return ((bytes[i++] & 0xFF) << 24) | ((bytes[i++] & 0xFF) << 16) | ((bytes[i++] & 0xFF) << 8) | (bytes[i++] & 0xFF);
    } catch (UnsupportedEncodingException ex) {
        throw new ElasticsearchException("cannot calculate hashcode", ex);
    } catch (NoSuchAlgorithmException ex) {
        throw new ElasticsearchException("cannot calculate hashcode", ex);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) ElasticsearchException(org.elasticsearch.ElasticsearchException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 2 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project che by eclipse.

the class CreateFileChange method perform.

@Override
public Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    InputStream is = null;
    try {
        pm.beginTask(NLSChangesMessages.createFile_creating_resource, 3);
        initializeEncoding();
        IFile file = getOldFile(new SubProgressMonitor(pm, 1));
        /*
			if (file.exists()) {
				CompositeChange composite= new CompositeChange(getName());
				composite.add(new DeleteFileChange(file));
				composite.add(new CreateFileChange(fPath, fSource, fEncoding, fStampToRestore, fExplicitEncoding));
				pm.worked(1);
				return composite.perform(new SubProgressMonitor(pm, 1));
			} else { */
        try {
            is = new ByteArrayInputStream(fSource.getBytes(fEncoding));
            file.create(is, false, new SubProgressMonitor(pm, 1));
            if (fStampToRestore != IResource.NULL_STAMP) {
                file.revertModificationStamp(fStampToRestore);
            }
            if (fExplicitEncoding) {
                file.setCharset(fEncoding, new SubProgressMonitor(pm, 1));
            } else {
                pm.worked(1);
            }
            return new DeleteResourceChange(file.getFullPath(), true);
        } catch (UnsupportedEncodingException e) {
            throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
        }
    } finally {
        try {
            if (is != null)
                is.close();
        } catch (IOException ioe) {
            throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
        } finally {
            pm.done();
        }
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DeleteResourceChange(org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 3 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project zeppelin by apache.

the class PegdownYumlPlugin method createYumlUrl.

public static String createYumlUrl(Map<String, String> params, String body) {
    StringBuilder inlined = new StringBuilder();
    for (String line : body.split("\\r?\\n")) {
        line = line.trim();
        if (line.length() > 0) {
            if (inlined.length() > 0) {
                inlined.append(", ");
            }
            inlined.append(line);
        }
    }
    String encodedBody = null;
    try {
        encodedBody = URLEncoder.encode(inlined.toString(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        new RuntimeException("Failed to encode YUML markdown body", e);
    }
    StringBuilder mergedStyle = new StringBuilder();
    String style = defaultString(params.get("style"), "scruffy");
    String type = defaultString(params.get("type"), "class");
    String format = defaultString(params.get("format"), "svg");
    mergedStyle.append(style);
    if (null != params.get("dir")) {
        mergedStyle.append(";dir:" + params.get("dir"));
    }
    if (null != params.get("scale")) {
        mergedStyle.append(";scale:" + params.get("scale"));
    }
    return new StringBuilder().append("http://yuml.me/diagram/").append(mergedStyle.toString() + "/").append(type + "/").append(encodedBody).append("." + format).toString();
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) StringUtils.defaultString(org.apache.commons.lang3.StringUtils.defaultString)

Example 4 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project tomcat by apache.

the class ApplicationPushBuilder method decode.

// Package private so it can be tested. charsetName must be in lower case.
static String decode(String input, String charsetName) {
    int start = input.indexOf('%');
    int end = 0;
    // Shortcut
    if (start == -1) {
        return input;
    }
    Charset charset;
    try {
        charset = B2CConverter.getCharsetLower(charsetName);
    } catch (UnsupportedEncodingException uee) {
        // before reaching here
        throw new IllegalStateException(uee);
    }
    StringBuilder result = new StringBuilder(input.length());
    while (start != -1) {
        // Found the start of a %nn sequence. Copy everything form the last
        // end to this start to the output.
        result.append(input.substring(end, start));
        // Advance the end 3 characters: %nn
        end = start + 3;
        while (end < input.length() && input.charAt(end) == '%') {
            end += 3;
        }
        result.append(decode(input.substring(start, end), charset));
        start = input.indexOf('%', end);
    }
    // Append the remaining text
    result.append(input.substring(end));
    return result.toString();
}
Also used : Charset(java.nio.charset.Charset) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project Openfire by igniterealtime.

the class StatsAction method getNLatestConversations.

/**
     * Retrieves the last n conversations from the system that were created after
     * the given conversationID.
     *
     * @param count the count of conversations to return.
     * @param mostRecentConversationID the last conversationID that has been retrieved.
     * @return a List of Map objects.
     */
public List<Map<String, Long>> getNLatestConversations(int count, long mostRecentConversationID) {
    // TODO Fix plugin name 2 lines below and missing classes
    List<Map<String, Long>> cons = new ArrayList<Map<String, Long>>();
    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
    ConversationManager conversationManager = (ConversationManager) plugin.getModule(ConversationManager.class);
    Collection<Conversation> conversations = conversationManager.getConversations();
    List<Conversation> lConversations = Arrays.asList(conversations.toArray(new Conversation[conversations.size()]));
    Collections.sort(lConversations, conversationComparator);
    int counter = 0;
    for (Iterator<Conversation> i = lConversations.iterator(); i.hasNext() && counter < count; ) {
        Conversation con = i.next();
        if (mostRecentConversationID == con.getConversationID()) {
            break;
        } else {
            Map mCon = new HashMap();
            mCon.put("conversationid", con.getConversationID());
            String[] users;
            int usersIdx = 0;
            if (con.getRoom() == null) {
                users = new String[con.getParticipants().size()];
                for (JID jid : con.getParticipants()) {
                    String identifier = jid.toBareJID();
                    try {
                        identifier = UserNameManager.getUserName(jid, jid.toBareJID());
                    } catch (UserNotFoundException e) {
                    // Ignore
                    }
                    users[usersIdx++] = StringUtils.abbreviate(identifier, 20);
                }
            } else {
                users = new String[2];
                users[0] = LocaleUtils.getLocalizedString("dashboard.group_conversation", MonitoringConstants.NAME);
                try {
                    users[1] = "(<i>" + LocaleUtils.getLocalizedString("muc.room.summary.room") + ": <a href='../../muc-room-occupants.jsp?roomName=" + URLEncoder.encode(con.getRoom().getNode(), "UTF-8") + "'>" + con.getRoom().getNode() + "</a></i>)";
                } catch (UnsupportedEncodingException e) {
                    Log.error(e.getMessage(), e);
                }
            }
            mCon.put("users", users);
            mCon.put("lastactivity", formatTimeLong(con.getLastActivity()));
            mCon.put("messages", con.getMessageCount());
            cons.add(0, mCon);
            counter++;
        }
    }
    return cons;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConversationManager(org.jivesoftware.openfire.archive.ConversationManager) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Conversation(org.jivesoftware.openfire.archive.Conversation) MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)3108 IOException (java.io.IOException)878 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)284 InputStream (java.io.InputStream)275 ArrayList (java.util.ArrayList)268 InputStreamReader (java.io.InputStreamReader)243 File (java.io.File)234 ByteArrayInputStream (java.io.ByteArrayInputStream)209 ByteArrayOutputStream (java.io.ByteArrayOutputStream)201 FileNotFoundException (java.io.FileNotFoundException)198 HashMap (java.util.HashMap)182 MessageDigest (java.security.MessageDigest)180 BufferedReader (java.io.BufferedReader)150 URL (java.net.URL)150 Map (java.util.Map)148 OutputStreamWriter (java.io.OutputStreamWriter)145 FileOutputStream (java.io.FileOutputStream)120 MalformedURLException (java.net.MalformedURLException)110 FileInputStream (java.io.FileInputStream)107 List (java.util.List)105