Java URL Load loadObject(URL url)

Here you can find the source of loadObject(URL url)

Description

load Object

License

Open Source License

Declaration

public static Object loadObject(URL url) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;

import java.net.URL;

import java.util.zip.*;

public class Main {
    public static Object loadObject(URL url) {
        return loadObject(url, false);
    }// www . j  a  v  a2 s  .  c om

    public static Object loadObject(URL url, boolean zipped) {
        try {
            return tryLoadObject(url, zipped);
        } catch (IOException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public static Object tryLoadObject(URL url) throws IOException, ClassNotFoundException {
        return tryLoadObject(url, false);
    }

    public static Object tryLoadObject(URL url, boolean zipped) throws IOException, ClassNotFoundException {
        InputStream input_stream = new BufferedInputStream(url.openStream());
        if (zipped)
            input_stream = new GZIPInputStream(input_stream);
        ObjectInputStream obj_stream;

        obj_stream = new ObjectInputStream(input_stream);
        Object obj = obj_stream.readObject();
        obj_stream.close();
        return obj;
    }
}

Related

  1. loadFromURL(URL url)
  2. loadFully(URL url)
  3. loadFully(URL url)
  4. loadImplementations(URL url, ClassLoader loader)
  5. loadManifest(URL url)
  6. loadProperties(final URL url)
  7. loadProperties(Properties p, URL url)
  8. loadProperties(URL url)
  9. loadProperties(URL url)