Search in sources :

Example 26 with InputMismatchException

use of java.util.InputMismatchException in project Neuronizer by djuelg.

the class EditItemInteractorImpl method run.

@Override
public void run() {
    final Optional<TodoListHeader> header = repository.todoList().getHeaderById(parentHeaderUuid);
    final Optional<TodoListItem> outDatedItem = repository.todoList().getItemById(uuid);
    if (!header.isPresent() || !outDatedItem.isPresent()) {
        throw new InputMismatchException("Header, or Item were not existing!");
    }
    final TodoListItem updatedItem = outDatedItem.get().update(title, position, important, details, done, parentHeaderUuid);
    repository.todoList().update(updatedItem);
    final Optional<TodoList> todoList = repository.todoList().getTodoListById(updatedItem.getParentTodoListUuid());
    final TodoListItem itemFromUI = new TodoListItem(uuid, title, outDatedItem.get().getCreatedAt(), outDatedItem.get().getChangedAt(), position, important, details, done, outDatedItem.get().getParentTodoListUuid(), parentHeaderUuid);
    if (todoList.isPresent() && !outDatedItem.get().equals(itemFromUI))
        repository.todoList().update(todoList.get().updateLastChange());
    mMainThread.post(new Runnable() {

        @Override
        public void run() {
            callback.onItemUpdated(updatedItem);
        }
    });
}
Also used : TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) InputMismatchException(java.util.InputMismatchException) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

Example 27 with InputMismatchException

use of java.util.InputMismatchException in project keyCard by paulr4321.

the class Console method getInputOption.

/**
 * Gets input from user. Input must be an integer. If input is not an integer, or if the input is not
 * one of the listed options, the user will be prompted until valid input is entered.
 * @param options string of options passed in by a state class
 *@return returns the option requested from the user
 */
public int getInputOption(String options) {
    int input = -1;
    boolean valid = false;
    String[] listOfOptions = options.split(",");
    while (!valid) {
        System.out.println("\nWhat would you like to do?\n");
        try {
            Scanner in = new Scanner(System.in);
            input = in.nextInt();
            valid = true;
        } catch (InputMismatchException e) {
            valid = false;
        }
        try {
            System.out.println("Option [" + listOfOptions[input] + "] was selected\n");
        } catch (ArrayIndexOutOfBoundsException e) {
            valid = false;
            System.out.println("Invalid input, please try again.\n");
        }
    }
    return input;
}
Also used : Scanner(java.util.Scanner) InputMismatchException(java.util.InputMismatchException)

Example 28 with InputMismatchException

use of java.util.InputMismatchException in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method applyConfig.

/**
 * API access to read extra properties from files.
 *
 * @param config
 *            the config
 * @param pathPrefix
 *            the path prefix
 */
public static void applyConfig(final RawConfigFile config, final String pathPrefix) {
    // Breaking time overrides for specific side conditions.
    ConfigurationSection section = config.getConfigurationSection(pathPrefix + ConfPaths.SUB_BREAKINGTIME);
    for (final String input : section.getKeys(false)) {
        try {
            BlockProperties.setBreakingTimeOverride(new BlockBreakKey().fromString(input.trim()), section.getLong(input));
        } catch (Exception e) {
            StaticLog.logWarning("Bad breaking time override (" + pathPrefix + ConfPaths.SUB_BREAKINGTIME + "): " + input);
            StaticLog.logWarning(e);
        }
    }
    // Allow instant breaking.
    for (final String input : config.getStringList(pathPrefix + ConfPaths.SUB_ALLOWINSTANTBREAK)) {
        final Material id = RawConfigFile.parseMaterial(input);
        if (id == null) {
            StaticLog.logWarning("Bad block id (" + pathPrefix + ConfPaths.SUB_ALLOWINSTANTBREAK + "): " + input);
        } else {
            setBlockProps(id, instantType);
        }
    }
    // Override block flags.
    section = config.getConfigurationSection(pathPrefix + ConfPaths.SUB_OVERRIDEFLAGS);
    if (section != null) {
        final Map<String, Object> entries = section.getValues(false);
        boolean hasErrors = false;
        for (final Entry<String, Object> entry : entries.entrySet()) {
            final String key = entry.getKey();
            final Material id = RawConfigFile.parseMaterial(key);
            if (id == null) {
                StaticLog.logWarning("Bad block id (" + pathPrefix + ConfPaths.SUB_OVERRIDEFLAGS + "): " + key);
                continue;
            }
            final Object obj = entry.getValue();
            if (!(obj instanceof String)) {
                StaticLog.logWarning("Bad flags at " + pathPrefix + ConfPaths.SUB_OVERRIDEFLAGS + " for key: " + key);
                hasErrors = true;
                continue;
            }
            final Collection<String> split = StringUtil.split((String) obj, ' ', ',', '/', '|', '+', ';', '\t');
            long flags = 0;
            boolean error = false;
            for (String input : split) {
                input = input.trim();
                if (input.isEmpty()) {
                    continue;
                } else if (input.equalsIgnoreCase("default")) {
                    flags |= getBlockFlags(id);
                    continue;
                }
                try {
                    flags |= parseFlag(input);
                } catch (InputMismatchException e) {
                    StaticLog.logWarning("Bad flag at " + pathPrefix + ConfPaths.SUB_OVERRIDEFLAGS + " for key " + key + " (skip setting flags for this block): " + input);
                    error = true;
                    hasErrors = true;
                    break;
                }
            }
            if (error) {
                continue;
            }
            setBlockFlags(id, flags);
        }
        if (hasErrors) {
            StaticLog.logInfo("Overriding block-flags was not entirely successful, all available flags: \n" + StringUtil.join(flagNameMap.values(), "|"));
        }
    }
}
Also used : Material(org.bukkit.Material) InputMismatchException(java.util.InputMismatchException) InputMismatchException(java.util.InputMismatchException) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 29 with InputMismatchException

use of java.util.InputMismatchException in project stdlib by petergeneric.

the class LogReport method unmarshal.

/**
 * Deserializes the object.
 * @param buf the data source.
 * @param offset the initial index for {@code buf}, inclusive.
 * @return the final index for {@code buf}, exclusive.
 * @throws BufferUnderflowException when {@code buf} is incomplete. (EOF)
 * @throws SecurityException on an upper limit breach defined by either {@link #colferSizeMax} or {@link #colferListMax}.
 * @throws InputMismatchException when the data does not match this object's schema.
 */
public int unmarshal(byte[] buf, int offset) {
    int i = offset;
    try {
        byte header = buf[i++];
        if (header == (byte) 0) {
            int size = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                size |= (b & 0x7f) << shift;
                if (shift == 28 || b >= 0)
                    break;
            }
            if (size > colferSizeMax)
                throw new SecurityException(format("colfer: field com/peterphi/std/guice/common/logging/logreport.LogReport.serviceId size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
            int start = i;
            i += size;
            this.serviceId = new String(buf, start, size, this._utf8);
            header = buf[i++];
        }
        if (header == (byte) 1) {
            int length = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                length |= (b & 0x7f) << shift;
                if (shift == 28 || b >= 0)
                    break;
            }
            if (length > colferListMax)
                throw new SecurityException(format("colfer: field com/peterphi/std/guice/common/logging/logreport.LogReport.lines length %d exceeds %d elements", length, colferListMax));
            LogLine[] a = new LogLine[length];
            for (int ai = 0; ai < length; ai++) {
                LogLine o = new LogLine();
                i = o.unmarshal(buf, i);
                a[ai] = o;
            }
            this.lines = a;
            header = buf[i++];
        }
        if (header != (byte) 0x7f)
            throw new InputMismatchException(format("colfer: unknown header at byte %d", i - 1));
    } catch (IndexOutOfBoundsException e) {
        if (i - offset > colferSizeMax)
            throw new SecurityException(format("colfer: serial exceeds %d bytes", colferSizeMax));
        if (i >= buf.length)
            throw new BufferUnderflowException();
        throw new RuntimeException("colfer: bug", e);
    }
    if (i - offset > colferSizeMax)
        throw new SecurityException(format("colfer: serial exceeds %d bytes", colferSizeMax));
    return i;
}
Also used : InputMismatchException(java.util.InputMismatchException) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 30 with InputMismatchException

use of java.util.InputMismatchException in project stdlib by petergeneric.

the class LogLine method unmarshal.

/**
 * Deserializes the object.
 * @param buf the data source.
 * @param offset the initial index for {@code buf}, inclusive.
 * @return the final index for {@code buf}, exclusive.
 * @throws BufferUnderflowException when {@code buf} is incomplete. (EOF)
 * @throws SecurityException on an upper limit breach defined by either {@link #colferSizeMax} or {@link #colferListMax}.
 * @throws InputMismatchException when the data does not match this object's schema.
 */
public int unmarshal(byte[] buf, int offset) {
    int i = offset;
    try {
        byte header = buf[i++];
        if (header == (byte) 0) {
            long x = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                if (shift == 56 || b >= 0) {
                    x |= (b & 0xffL) << shift;
                    break;
                }
                x |= (b & 0x7fL) << shift;
            }
            this.when = x;
            header = buf[i++];
        } else if (header == (byte) (0 | 0x80)) {
            long x = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                if (shift == 56 || b >= 0) {
                    x |= (b & 0xffL) << shift;
                    break;
                }
                x |= (b & 0x7fL) << shift;
            }
            this.when = -x;
            header = buf[i++];
        }
        if (header == (byte) 1) {
            int size = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                size |= (b & 0x7f) << shift;
                if (shift == 28 || b >= 0)
                    break;
            }
            if (size > colferSizeMax)
                throw new SecurityException(format("colfer: field com/peterphi/std/guice/common/logging/logreport.LogLine.category size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
            int start = i;
            i += size;
            this.category = new String(buf, start, size, this._utf8);
            header = buf[i++];
        }
        if (header == (byte) 2) {
            int x = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                x |= (b & 0x7f) << shift;
                if (shift == 28 || b >= 0)
                    break;
            }
            this.level = x;
            header = buf[i++];
        } else if (header == (byte) (2 | 0x80)) {
            this.level = (buf[i++] & 0xff) << 24 | (buf[i++] & 0xff) << 16 | (buf[i++] & 0xff) << 8 | (buf[i++] & 0xff);
            header = buf[i++];
        }
        if (header == (byte) 3) {
            int size = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                size |= (b & 0x7f) << shift;
                if (shift == 28 || b >= 0)
                    break;
            }
            if (size > colferSizeMax)
                throw new SecurityException(format("colfer: field com/peterphi/std/guice/common/logging/logreport.LogLine.requestUri size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
            int start = i;
            i += size;
            this.requestUri = new String(buf, start, size, this._utf8);
            header = buf[i++];
        }
        if (header == (byte) 4) {
            int size = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                size |= (b & 0x7f) << shift;
                if (shift == 28 || b >= 0)
                    break;
            }
            if (size > colferSizeMax)
                throw new SecurityException(format("colfer: field com/peterphi/std/guice/common/logging/logreport.LogLine.thread size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
            int start = i;
            i += size;
            this.thread = new String(buf, start, size, this._utf8);
            header = buf[i++];
        }
        if (header == (byte) 5) {
            int size = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                size |= (b & 0x7f) << shift;
                if (shift == 28 || b >= 0)
                    break;
            }
            if (size > colferSizeMax)
                throw new SecurityException(format("colfer: field com/peterphi/std/guice/common/logging/logreport.LogLine.userId size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
            int start = i;
            i += size;
            this.userId = new String(buf, start, size, this._utf8);
            header = buf[i++];
        }
        if (header == (byte) 6) {
            int size = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                size |= (b & 0x7f) << shift;
                if (shift == 28 || b >= 0)
                    break;
            }
            if (size > colferSizeMax)
                throw new SecurityException(format("colfer: field com/peterphi/std/guice/common/logging/logreport.LogLine.traceId size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
            int start = i;
            i += size;
            this.traceId = new String(buf, start, size, this._utf8);
            header = buf[i++];
        }
        if (header == (byte) 7) {
            int size = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                size |= (b & 0x7f) << shift;
                if (shift == 28 || b >= 0)
                    break;
            }
            if (size > colferSizeMax)
                throw new SecurityException(format("colfer: field com/peterphi/std/guice/common/logging/logreport.LogLine.exceptionId size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
            int start = i;
            i += size;
            this.exceptionId = new String(buf, start, size, this._utf8);
            header = buf[i++];
        }
        if (header == (byte) 8) {
            int size = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                size |= (b & 0x7f) << shift;
                if (shift == 28 || b >= 0)
                    break;
            }
            if (size > colferSizeMax)
                throw new SecurityException(format("colfer: field com/peterphi/std/guice/common/logging/logreport.LogLine.exception size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
            int start = i;
            i += size;
            this.exception = new String(buf, start, size, this._utf8);
            header = buf[i++];
        }
        if (header == (byte) 9) {
            int size = 0;
            for (int shift = 0; true; shift += 7) {
                byte b = buf[i++];
                size |= (b & 0x7f) << shift;
                if (shift == 28 || b >= 0)
                    break;
            }
            if (size > colferSizeMax)
                throw new SecurityException(format("colfer: field com/peterphi/std/guice/common/logging/logreport.LogLine.message size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
            int start = i;
            i += size;
            this.message = new String(buf, start, size, this._utf8);
            header = buf[i++];
        }
        if (header != (byte) 0x7f)
            throw new InputMismatchException(format("colfer: unknown header at byte %d", i - 1));
    } catch (IndexOutOfBoundsException e) {
        if (i - offset > colferSizeMax)
            throw new SecurityException(format("colfer: serial exceeds %d bytes", colferSizeMax));
        if (i >= buf.length)
            throw new BufferUnderflowException();
        throw new RuntimeException("colfer: bug", e);
    }
    if (i - offset > colferSizeMax)
        throw new SecurityException(format("colfer: serial exceeds %d bytes", colferSizeMax));
    return i;
}
Also used : InputMismatchException(java.util.InputMismatchException) BufferUnderflowException(java.nio.BufferUnderflowException)

Aggregations

InputMismatchException (java.util.InputMismatchException)82 Scanner (java.util.Scanner)56 NoSuchElementException (java.util.NoSuchElementException)47 Locale (java.util.Locale)23 BufferUnderflowException (java.nio.BufferUnderflowException)5 Pattern (java.util.regex.Pattern)5 BufferedReader (java.io.BufferedReader)4 BigInteger (java.math.BigInteger)4 UnicodeReader (gdsc.core.utils.UnicodeReader)3 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 TodoList (de.djuelg.neuronizer.domain.model.preview.TodoList)2 TodoListHeader (de.djuelg.neuronizer.domain.model.todolist.TodoListHeader)2 Point (java.awt.Point)2 Serializable (java.io.Serializable)2 BigDecimal (java.math.BigDecimal)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1