Example usage for java.io InvalidObjectException InvalidObjectException

List of usage examples for java.io InvalidObjectException InvalidObjectException

Introduction

In this page you can find the example usage for java.io InvalidObjectException InvalidObjectException.

Prototype

public InvalidObjectException(String reason) 

Source Link

Document

Constructs an InvalidObjectException.

Usage

From source file:org.lenskit.data.entities.TypedName.java

private void readObject(ObjectInputStream in) throws IOException {
    throw new InvalidObjectException("typed names must use serialization proxy");
}

From source file:org.lenskit.data.entities.TypedName.java

private void readObjectNoData() throws ObjectStreamException {
    throw new InvalidObjectException("typed names must use serialization proxy");
}

From source file:org.grouplens.grapht.context.TypeElementMatcher.java

private void readObject(ObjectInputStream stream) throws ObjectStreamException {
    throw new InvalidObjectException("must use serialization proxy");
}

From source file:org.grouplens.lenskit.data.dao.packed.BinaryRatingDAO.java

private void readObject(ObjectInputStream in) throws IOException {
    throw new InvalidObjectException("attempted to read BinaryRatingDAO without proxy");
}

From source file:com.bigtobster.pgnextractalt.commands.IOCommands.java

/**
 * Exports the currently loaded list of games to a text PGN file
 *
 * @param file File to be imported/*from  w ww  .jav  a2s  .  c  o m*/
 * @return Successful export of PGN file
 */
@CliCommand(value = IOCommands.EXPORT_COMMAND, help = IOCommands.EXPORT_COMMAND_HELP)
public String exportPGN(@CliOption(key = {
        IOCommands.FILE_PATH_OPTION }, help = "Path (including file name) for exported PGN. File will be "
                + "created if it doesn't exist.", mandatory = true) final File file) {
    final PrintWriter printWriter;
    String failureDetails = null;
    final String filePath = file.getAbsolutePath();
    try {
        if (!file.exists()) {
            //noinspection ResultOfMethodCallIgnored
            file.getParentFile().mkdirs();
            //noinspection ResultOfMethodCallIgnored
            file.createNewFile();
        }
        if (!file.canRead() || !file.canWrite()) {
            //noinspection ThrowCaughtLocally
            throw new InvalidObjectException(IOCommands.PGN_NOT_WRITABLE + IOCommands.SPACE + filePath);
        }
        printWriter = new PrintWriter(file);
        try {
            this.commandContext.getChessIO().exportPGN(printWriter);
        } finally {
            printWriter.close();
        }
    } catch (final FileNotFoundException ignored) {
        failureDetails = IOCommands.CANNOT_CREATE_FILE + IOCommands.SPACE + filePath;
    } catch (final InvalidObjectException ioe) {
        failureDetails = ioe.getMessage();
    } catch (final IOException ignored) {
        failureDetails = IOCommands.CANNOT_CREATE_FILE + IOCommands.SPACE + filePath;
    }
    if (failureDetails == null) {
        return IOCommands.SUCCESSFUL_EXPORT + IOCommands.SPACE
                + this.commandContext.getChessIO().getGames().size() + IOCommands.SPACE
                + IOCommands.GAMES_EXPORTED;
    }
    return IOCommands.FAILED_EXPORT + IOCommands.SPACE + failureDetails;
}

From source file:ru.emdev.ldap.util.EmDevSchemaLdifExtractor.java

/**
 * Copies a file line by line from the source file argument to the 
 * destination file argument./*from   w w  w. ja v a2s  . com*/
 *
 * @param source the source file to copy
 * @param destination the destination to copy the source to
 * @throws IOException if there are IO errors or the source does not exist
 */
private void copyFile(File source, File destination) throws IOException {
    LOG.debug("copyFile(): source = {}, destination = {}", source, destination);

    if (!destination.getParentFile().exists() && !destination.getParentFile().mkdirs()) {
        throw new IOException(
                I18n.err("Directory Creation Failed: " + destination.getParentFile().getAbsolutePath()));
    }

    if (!source.getParentFile().exists()) {
        throw new FileNotFoundException(I18n.err(I18n.ERR_08002, source.getAbsolutePath()));
    }

    FileWriter out = new FileWriter(destination);

    try {
        LdifReader ldifReader = new LdifReader(source);
        boolean first = true;
        LdifEntry ldifEntry = null;

        while (ldifReader.hasNext()) {
            if (first) {
                ldifEntry = ldifReader.next();

                if (ldifEntry.get(SchemaConstants.ENTRY_UUID_AT) == null) {
                    // No UUID, let's create one
                    UUID entryUuid = UUID.randomUUID();
                    ldifEntry.addAttribute(SchemaConstants.ENTRY_UUID_AT, entryUuid.toString());
                }

                first = false;
            } else {
                // throw an exception : we should not have more than one entry per schema ldif file
                String msg = I18n.err(I18n.ERR_08003, source);
                LOG.error(msg);
                throw new InvalidObjectException(msg);
            }
        }

        ldifReader.close();

        // Add the version at the first line, to avoid a warning
        String ldifString = "version: 1\n" + ldifEntry.toString();

        out.write(ldifString);
        out.flush();
    } catch (LdapLdifException ne) {
        // throw an exception : we should not have more than one entry per schema ldif file
        String msg = I18n.err(I18n.ERR_08004, source, ne.getLocalizedMessage());
        LOG.error(msg);
        throw new InvalidObjectException(msg);
    } catch (LdapException ne) {
        // throw an exception : we should not have more than one entry per schema ldif file
        String msg = I18n.err(I18n.ERR_08004, source, ne.getLocalizedMessage());
        LOG.error(msg);
        throw new InvalidObjectException(msg);
    } finally {
        out.close();
    }
}

From source file:org.apereo.portal.portlet.registry.PortletWindowData.java

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    //Read & validate non-transient fields
    ois.defaultReadObject();/*from w  w w.  j  av  a2  s  .co m*/

    if (this.portletWindowId == null) {
        throw new InvalidObjectException("portletWindowId can not be null");
    }
    if (this.portletEntityId == null) {
        throw new InvalidObjectException("portletEntityId can not be null");
    }

    //Read & validate transient fields
    final String portletModeStr = (String) ois.readObject();
    if (portletModeStr == null) {
        throw new InvalidObjectException("portletMode can not be null");
    }
    this.portletMode = PortletUtils.getPortletMode(portletModeStr);

    final String windowStateStr = (String) ois.readObject();
    if (windowStateStr == null) {
        throw new InvalidObjectException("windowState can not be null");
    }
    this.windowState = PortletUtils.getWindowState(windowStateStr);
}

From source file:org.asamk.signal.Manager.java

private JsonNode getNotNullNode(JsonNode parent, String name) throws InvalidObjectException {
    JsonNode node = parent.get(name);//from  ww w.  jav a 2  s. c o m
    if (node == null) {
        throw new InvalidObjectException(
                String.format("Incorrect file format: expected parameter %s not found ", name));
    }

    return node;
}

From source file:com.bigtobster.pgnextractalt.commands.IOCommands.java

/**
 * Imports a text PGN file to a list of Chesspresso games
 *
 * @param file The file to be imported/*  ww w .ja  v a 2  s.  c o m*/
 * @return Successful import of PGN file
 * @throws java.io.IOException Crashes on unknown failure to open PGN file
 */
@SuppressWarnings({ "FeatureEnvy", "ProhibitedExceptionDeclared" })
@CliCommand(value = IOCommands.IMPORT_COMMAND, help = IOCommands.IMPORT_COMMAND_HELP)
public String importPGN(@CliOption(key = {
        IOCommands.FILE_PATH_OPTION }, help = "Path to the PGN file to be imported", mandatory = true) final File file)
        throws Exception {
    String failureDetails = null;
    final String filePath = file.getPath();
    try {
        if (!file.canRead() && file.exists()) {
            //noinspection ThrowCaughtLocally
            throw new InvalidObjectException(IOCommands.PGN_NOT_READABLE + IOCommands.SPACE + filePath);
        }
        try {
            this.commandContext.getChessIO().importPGN(file);
        } catch (final UnsupportedDataTypeException ignored) {
            failureDetails = IOCommands.NOT_A_PGN_FILE;
        } catch (final IOException ioe) {
            failureDetails = CommandContext.UNKNOWN_IMPORT_ERROR + OsUtils.LINE_SEPARATOR
                    + CommandContext.NOTIFY_DEV;
            CommandContext.handleAndThrowSevereError(ioe, failureDetails);
        } catch (final PGNSyntaxError ignored) {
            failureDetails = IOCommands.INVALID_SYNTAX;
        }
    } catch (final FileNotFoundException ignored) {
        failureDetails = IOCommands.NO_FILE_AT + IOCommands.SPACE + filePath;
    } catch (final InvalidObjectException ioe) {
        failureDetails = ioe.getMessage();
    }
    if (this.commandContext.getChessIO().getGames().size() < 0) {
        failureDetails = IOCommands.NO_CHESS_GAMES;
    }
    if (failureDetails == null) {
        return IOCommands.SUCCESSFUL_IMPORT + IOCommands.SPACE
                + this.commandContext.getChessIO().getGames().size() + IOCommands.SPACE
                + IOCommands.GAMES_IMPORTED;
    }
    return IOCommands.FAILED_IMPORT + IOCommands.SPACE + failureDetails;
}

From source file:com.microsoft.azure.management.datalake.store.uploader.UploadMetadata.java

/**
 * Saves the given metadata to its canonical location. This method is thread-safe.
 *
 * @throws IOException Thrown if the file cannot be saved due to accessibility or there is an error saving the stream to disk.
 * @throws InvalidMetadataException Thrown if the metadata is invalid.
 *//* w w w  .j  a  v  a2s.c o  m*/
public void save() throws IOException, InvalidMetadataException {
    if (this.metadataFilePath == null || StringUtils.isEmpty(this.metadataFilePath)) {
        throw new InvalidObjectException(
                "Null or empty metadataFilePath. Cannot save metadata until this property is set.");
    }

    //quick check to ensure that the metadata we constructed is sane
    this.validateConsistency();

    synchronized (saveSync) {
        File curMetadata = new File(this.metadataFilePath);
        if (curMetadata.exists()) {
            curMetadata.delete();
        }

        // always create the full path to the file, since this will not throw if it already exists.
        curMetadata.getParentFile().mkdirs();
        curMetadata.createNewFile();
        try {
            FileOutputStream fileOut = new FileOutputStream(this.metadataFilePath);
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            out.writeObject(this);
            out.close();
            fileOut.close();
        } catch (Exception ex) {
            throw new InvalidMetadataException("Unable to parse metadata object and write it to a file", ex);
        }
    }
}