Search in sources :

Example 51 with NoSuchElementException

use of java.util.NoSuchElementException in project alluxio by Alluxio.

the class ByteBufferKeyValuePartitionReader method iterator.

@Override
public KeyValueIterator iterator() {
    return new KeyValueIterator() {

        private Iterator<ByteBuffer> mKeyIterator = mIndex.keyIterator(mPayloadReader);

        @Override
        public boolean hasNext() {
            return mKeyIterator.hasNext();
        }

        @Override
        public KeyValuePair next() throws IOException, AlluxioException {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            ByteBuffer key = mKeyIterator.next();
            ByteBuffer value = get(key);
            return new KeyValuePair(key, value);
        }
    };
}
Also used : Iterator(java.util.Iterator) ByteBuffer(java.nio.ByteBuffer) NoSuchElementException(java.util.NoSuchElementException)

Example 52 with NoSuchElementException

use of java.util.NoSuchElementException in project opennms by OpenNMS.

the class TestAgent method getFollowingObjId.

public SnmpObjId getFollowingObjId(SnmpObjId id) {
    try {
        SnmpObjId nextObjId = m_agentData.tailMap(SnmpObjId.get(id, SnmpInstId.INST_ZERO)).firstKey();
        Object value = m_agentData.get(nextObjId);
        if (value instanceof Redirect) {
            Redirect redirect = (Redirect) value;
            return redirect.getTargetObjId();
        }
        return nextObjId;
    } catch (NoSuchElementException e) {
        throw new AgentEndOfMibException();
    }
}
Also used : SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) NoSuchElementException(java.util.NoSuchElementException)

Example 53 with NoSuchElementException

use of java.util.NoSuchElementException in project android_frameworks_base by DirtyUnicorns.

the class NetworkManagementService method getNetworkStatsTethering.

@Override
public NetworkStats getNetworkStatsTethering() {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1);
    try {
        final NativeDaemonEvent[] events = mConnector.executeForList("bandwidth", "gettetherstats");
        for (NativeDaemonEvent event : events) {
            if (event.getCode() != TetheringStatsListResult)
                continue;
            // 114 ifaceIn ifaceOut rx_bytes rx_packets tx_bytes tx_packets
            final StringTokenizer tok = new StringTokenizer(event.getMessage());
            try {
                final String ifaceIn = tok.nextToken();
                final String ifaceOut = tok.nextToken();
                final NetworkStats.Entry entry = new NetworkStats.Entry();
                entry.iface = ifaceOut;
                entry.uid = UID_TETHERING;
                entry.set = SET_DEFAULT;
                entry.tag = TAG_NONE;
                entry.rxBytes = Long.parseLong(tok.nextToken());
                entry.rxPackets = Long.parseLong(tok.nextToken());
                entry.txBytes = Long.parseLong(tok.nextToken());
                entry.txPackets = Long.parseLong(tok.nextToken());
                stats.combineValues(entry);
            } catch (NoSuchElementException e) {
                throw new IllegalStateException("problem parsing tethering stats: " + event);
            } catch (NumberFormatException e) {
                throw new IllegalStateException("problem parsing tethering stats: " + event);
            }
        }
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
    return stats;
}
Also used : StringTokenizer(java.util.StringTokenizer) NetworkStats(android.net.NetworkStats) NoSuchElementException(java.util.NoSuchElementException)

Example 54 with NoSuchElementException

use of java.util.NoSuchElementException in project android_frameworks_base by DirtyUnicorns.

the class NetworkManagementService method getInterfaceConfig.

@Override
public InterfaceConfiguration getInterfaceConfig(String iface) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    final NativeDaemonEvent event;
    try {
        event = mConnector.execute("interface", "getcfg", iface);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
    event.checkCode(InterfaceGetCfgResult);
    // Rsp: 213 xx:xx:xx:xx:xx:xx yyy.yyy.yyy.yyy zzz flag1 flag2 flag3
    final StringTokenizer st = new StringTokenizer(event.getMessage());
    InterfaceConfiguration cfg;
    try {
        cfg = new InterfaceConfiguration();
        cfg.setHardwareAddress(st.nextToken(" "));
        InetAddress addr = null;
        int prefixLength = 0;
        try {
            addr = NetworkUtils.numericToInetAddress(st.nextToken());
        } catch (IllegalArgumentException iae) {
            Slog.e(TAG, "Failed to parse ipaddr", iae);
        }
        try {
            prefixLength = Integer.parseInt(st.nextToken());
        } catch (NumberFormatException nfe) {
            Slog.e(TAG, "Failed to parse prefixLength", nfe);
        }
        cfg.setLinkAddress(new LinkAddress(addr, prefixLength));
        while (st.hasMoreTokens()) {
            cfg.setFlag(st.nextToken());
        }
    } catch (NoSuchElementException nsee) {
        throw new IllegalStateException("Invalid response from daemon: " + event);
    }
    return cfg;
}
Also used : LinkAddress(android.net.LinkAddress) StringTokenizer(java.util.StringTokenizer) InterfaceConfiguration(android.net.InterfaceConfiguration) InetAddress(java.net.InetAddress) NoSuchElementException(java.util.NoSuchElementException)

Example 55 with NoSuchElementException

use of java.util.NoSuchElementException in project intellij-community by JetBrains.

the class JavaElementSignatureProvider method restoreBySignatureTokens.

@Override
protected PsiElement restoreBySignatureTokens(@NotNull PsiFile file, @NotNull PsiElement parent, @NotNull String type, @NotNull StringTokenizer tokenizer, @Nullable StringBuilder processingInfoStorage) {
    if (type.equals("imports")) {
        return file instanceof PsiJavaFile ? ((PsiJavaFile) file).getImportList() : null;
    } else if (type.equals("method")) {
        String name = tokenizer.nextToken();
        try {
            int index = Integer.parseInt(tokenizer.nextToken());
            return restoreElementInternal(parent, name, index, PsiMethod.class);
        } catch (NumberFormatException e) {
            LOG.error(e);
            return null;
        }
    } else if (type.equals("class")) {
        String name = tokenizer.nextToken();
        PsiNameHelper nameHelper = PsiNameHelper.getInstance(file.getProject());
        if (nameHelper.isIdentifier(name)) {
            int index = 0;
            try {
                index = Integer.parseInt(tokenizer.nextToken());
            } catch (NoSuchElementException e) {
            //To read previous XML versions correctly
            }
            return restoreElementInternal(parent, name, index, PsiClass.class);
        }
        StringTokenizer tok1 = new StringTokenizer(name, ":");
        int start = Integer.parseInt(tok1.nextToken());
        int end = Integer.parseInt(tok1.nextToken());
        PsiElement element = file.findElementAt(start);
        if (element != null) {
            TextRange range = element.getTextRange();
            while (range != null && range.getEndOffset() < end) {
                element = element.getParent();
                range = element.getTextRange();
            }
            if (range != null && range.getEndOffset() == end && element instanceof PsiClass) {
                return element;
            }
        }
        return null;
    } else if (type.equals("initializer")) {
        try {
            int index = Integer.parseInt(tokenizer.nextToken());
            PsiElement[] children = parent.getChildren();
            for (PsiElement child : children) {
                if (child instanceof PsiClassInitializer) {
                    if (index == 0) {
                        return child;
                    }
                    index--;
                }
            }
            return null;
        } catch (NumberFormatException e) {
            LOG.error(e);
            return null;
        }
    } else if (type.equals("field")) {
        String name = tokenizer.nextToken();
        try {
            int index = 0;
            try {
                index = Integer.parseInt(tokenizer.nextToken());
            } catch (NoSuchElementException e) {
            //To read previous XML versions correctly
            }
            return restoreElementInternal(parent, name, index, PsiField.class);
        } catch (NumberFormatException e) {
            LOG.error(e);
            return null;
        }
    } else if (type.equals("docComment")) {
        if (parent instanceof PsiClass) {
            return ((PsiClass) parent).getDocComment();
        } else if (parent instanceof PsiMethod) {
            return ((PsiMethod) parent).getDocComment();
        } else if (parent instanceof PsiField) {
            return ((PsiField) parent).getDocComment();
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : TextRange(com.intellij.openapi.util.TextRange) StringTokenizer(java.util.StringTokenizer) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

NoSuchElementException (java.util.NoSuchElementException)1629 Iterator (java.util.Iterator)234 ArrayList (java.util.ArrayList)138 IOException (java.io.IOException)137 Test (org.junit.Test)95 StringTokenizer (java.util.StringTokenizer)88 Scanner (java.util.Scanner)86 Map (java.util.Map)56 List (java.util.List)54 File (java.io.File)51 HashMap (java.util.HashMap)47 InputMismatchException (java.util.InputMismatchException)47 LinkedList (java.util.LinkedList)32 HashSet (java.util.HashSet)31 Set (java.util.Set)29 CorruptDataException (com.ibm.j9ddr.CorruptDataException)28 Locale (java.util.Locale)27 Collection (java.util.Collection)26 BufferedReader (java.io.BufferedReader)24 Enumeration (java.util.Enumeration)24