Example usage for java.io StreamCorruptedException StreamCorruptedException

List of usage examples for java.io StreamCorruptedException StreamCorruptedException

Introduction

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

Prototype

public StreamCorruptedException(String reason) 

Source Link

Document

Create a StreamCorruptedException and list a reason why thrown.

Usage

From source file:com.seajas.search.utilities.remoting.JsonInvokerServiceExporter.java

private static final JsonToken openField(String name, JsonParser parser) throws IOException {
    System.err.println(parser.nextToken());
    if (!name.equals(parser.getCurrentName())) {
        String msg = String.format("Expected field %s instead of %s", name, parser.getCurrentName());
        throw new StreamCorruptedException(msg);
    }/*from w ww .  jav  a  2 s.  c  o  m*/
    return parser.nextToken();
}

From source file:com.seajas.search.utilities.remoting.JsonInvokerRequestExecutor.java

@Override
protected RemoteInvocationResult readRemoteInvocationResult(InputStream is, String codebaseUrl)
        throws IOException {
    JsonParser parser = factory.createJsonParser(is);
    parser.setCodec(codec);/*from w w w  .  j  a v a 2s . c  o m*/

    System.err.println(parser.nextToken());
    System.err.println(parser.nextToken());
    if (!"type".equals(parser.getCurrentName()))
        throw new StreamCorruptedException("Expected type field instead of " + parser.getCurrentName());
    System.err.println(parser.nextToken());
    Class<?> type = null;
    try {
        type = Class.forName(parser.getText());
    } catch (ClassNotFoundException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

    System.err.println(parser.nextToken());
    if (!"content".equals(parser.getCurrentName()))
        throw new StreamCorruptedException("Expected content field instead of " + parser.getCurrentName());
    System.err.println(parser.nextToken());
    Object content = parser.readValueAs(type);
    if (content instanceof Throwable)
        return new RemoteInvocationResult((Throwable) content);
    return new RemoteInvocationResult(content);
}

From source file:de.tuebingen.uni.sfs.germanet.api.StaxLoader.java

/**
 * Constructs a <code>StaxLoader</code> for data streams in
 * <code>germanetStreams</code> and existing <code>GermaNet</code> object
 * <code>germaNet</code>./* ww w  .  j ava 2 s . c  o  m*/
 * @param germanetDirectory location of GermaNet data files
 * @param germaNet <code>GermaNet</code> object to load into
 * @throws java.io.FileNotFoundException
 */
protected StaxLoader(List<InputStream> germaNetStreams, List<String> xmlNames, GermaNet germaNet)
        throws StreamCorruptedException {
    this.germaNetStreams = germaNetStreams;
    this.germaNetDir = null;
    this.synLoader = new SynsetLoader(germaNet);
    this.relLoader = new RelationLoader(germaNet);
    this.xmlNames = xmlNames;

    if (germaNetStreams.isEmpty()) {
        throw new StreamCorruptedException("Unable to load GermaNet from \"" + germaNetStreams + "\"");
    }
}

From source file:de.tuebingen.uni.sfs.germanet.api.StaxLoader.java

/**
 * Loads all synset files or streams (depending on what exists) and then all relation files.
 * @throws java.io.FileNotFoundException
 * @throws javax.xml.stream.XMLStreamException
 *///from  w w w.  j a  v  a2s  .  c  om
protected void load() throws XMLStreamException {
    if (this.germaNetDir != null) { // load GermaNet from file
        FilenameFilter filter = new SynsetFilter(); //get only synset files

        File[] germaNetFiles = germaNetDir.listFiles(filter);

        try {
            if (germaNetFiles == null || germaNetFiles.length == 0) {
                throw new FileNotFoundException(
                        "Unable to load GermaNet from \"" + this.germaNetDir.getPath() + "\"");
            }

            // load all synset files first with a SynsetLoader
            for (File germaNetFile : germaNetFiles) {
                logger.debug("Loading " + germaNetFile.getName() + "...");
                synLoader.loadSynsets(germaNetFile);
            }

            filter = new RelationFilter(); //get only relatin files

            germaNetFiles = germaNetDir.listFiles(filter);

            // load relations with a RelationLoader
            for (File germaNetFile : germaNetFiles) {
                logger.debug("Loading " + germaNetFile.getName() + "...");
                relLoader.loadRelations(germaNetFile);
            }
            logger.debug("Done.");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(StaxLoader.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else { // load GermaNet from InputStream list
        if (germaNetStreams == null || germaNetStreams.isEmpty()) {
            try {
                throw new StreamCorruptedException("Unable to load GermaNet from input stream \""
                        + this.germaNetStreams.toString() + "\"");
            } catch (StreamCorruptedException ex) {
                Logger.getLogger(StaxLoader.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        // load all synset input streams first with a SynsetLoader
        for (int i = 0; i < germaNetStreams.size(); i++) {

            if (xmlNames.get(i).endsWith("xml") && (xmlNames.get(i).startsWith("nomen")
                    || xmlNames.get(i).startsWith("verben") || xmlNames.get(i).startsWith("adj"))) {
                logger.debug("Loading input stream " + xmlNames.get(i) + "...");
                synLoader.loadSynsets(germaNetStreams.get(i));
            }
        }

        // load relations with a RelationLoader
        for (int i = 0; i < germaNetStreams.size(); i++) {
            if (xmlNames.get(i).equals("gn_relations.xml")) {
                logger.debug("Loading input stream " + xmlNames.get(i) + "...");
                relLoader.loadRelations(germaNetStreams.get(i));
            }
        }
        logger.debug("Done.");
    }
}

From source file:net.community.chest.gitcloud.facade.AbstractContextInitializer.java

protected SortedSet<File> ensureFoldersExistence(File appBase, File configFile,
        ExtendedPlaceholderResolver sourcesResolver) throws IOException {
    Properties props = new Properties();
    InputStream propsStream = new BufferedInputStream(new FileInputStream(configFile));
    try {//from w  ww  . ja v a 2  s  .  c o  m
        props.load(propsStream);
    } finally {
        propsStream.close();
    }

    String prev = props.getProperty(ConfigUtils.GITCLOUD_BASE_PROP);
    if (!StringUtils.isEmpty(prev)) {
        throw new StreamCorruptedException(ConfigUtils.GITCLOUD_BASE_PROP + " property re-specified: " + prev);
    }

    return ensureFoldersExistence(appBase, ExtendedPlaceholderResolverUtils.toPlaceholderResolver(props),
            sourcesResolver);
}

From source file:net.community.chest.gitcloud.facade.AbstractEnvironmentInitializer.java

protected void extractConfigFiles(File confDir, String resPrefix, Collection<String> names) {
    if (ConfigUtils.verifyFolderProperty(ConfigUtils.CONF_DIR_NAME, confDir)) {
        logger.info("extractConfigFiles(" + resPrefix + ") - created " + ExtendedFileUtils.toString(confDir));
    }/*w ww. j  a va 2  s.  co  m*/

    ClassLoader cl = ExtendedClassUtils.getDefaultClassLoader(getClass());
    for (String fileName : names) {
        File targetFile = new File(confDir, fileName);
        if (targetFile.exists()) {
            logger.info("extractConfigFiles(" + fileName + ")[" + resPrefix + "] skip - already exists: "
                    + ExtendedFileUtils.toString(targetFile));
            continue;
        }

        try {
            long copyLength = extractConfigFile(cl.getResourceAsStream(resPrefix + "/" + fileName), targetFile,
                    getWorkBuf(ExtendedIOUtils.DEFAULT_BUFFER_SIZE_VALUE));
            if (copyLength <= 0L) {
                throw new StreamCorruptedException("Bad copy count: " + copyLength);
            }

            logger.info("extractConfigFiles(" + resPrefix + ")[" + fileName + "] " + copyLength + " bytes: "
                    + ExtendedFileUtils.toString(targetFile));
        } catch (IOException e) {
            RuntimeException thrown = new RuntimeException(
                    "extractConfigFiles(" + resPrefix + ")[" + fileName + "]" + " failed ("
                            + e.getClass().getSimpleName() + ")" + " to extract contents: " + e.getMessage(),
                    e);
            logger.warn(thrown.getMessage(), e);
            throw thrown;
        }
    }
}

From source file:org.grouplens.grapht.annotation.AnnotationProxy.java

/**
 * Customized {@code readObject} implementation to ensure the cached type is resolved.
 *
 * @param in The stream.//w  w w  .  j av  a 2  s . c  om
 * @throws java.io.ObjectStreamException If there is an error reading the object from the stream.
 */
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws ObjectStreamException {
    try {
        in.defaultReadObject();
        cachedType = (Class<T>) annotationType.resolve();
    } catch (IOException e) {
        ObjectStreamException ex = new StreamCorruptedException("IO exception");
        ex.initCause(e);
        throw ex;
    } catch (ClassNotFoundException e) {
        ObjectStreamException ex = new InvalidObjectException("IO exception");
        ex.initCause(e);
        throw ex;
    }
}