List of usage examples for java.io ObjectInputStream readUTF
public String readUTF() throws IOException
From source file:com.flowpowered.api.geo.discrete.Point.java
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject();/*from ww w. j av a 2 s. c o m*/ String world = in.readUTF(); World w = Flow.getEngine().getWorldManager().getWorld(world, true); try { Field field; field = Point.class.getDeclaredField("world"); field.setAccessible(true); field.set(this, w); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { if (Flow.debugMode()) { e.printStackTrace(); } } }
From source file:eu.stratosphere.hadoopcompatibility.mapreduce.HadoopInputFormat.java
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String hadoopInputFormatClassName = in.readUTF(); String keyClassName = in.readUTF(); String valueClassName = in.readUTF(); org.apache.hadoop.conf.Configuration configuration = new org.apache.hadoop.conf.Configuration(); configuration.readFields(in);/*from ww w.j av a 2 s . c o m*/ if (this.configuration == null) { this.configuration = configuration; } try { this.mapreduceInputFormat = (org.apache.hadoop.mapreduce.InputFormat<K, V>) Class .forName(hadoopInputFormatClassName, true, Thread.currentThread().getContextClassLoader()) .newInstance(); } catch (Exception e) { throw new RuntimeException("Unable to instantiate the hadoop input format", e); } try { this.keyClass = (Class<K>) Class.forName(keyClassName, true, Thread.currentThread().getContextClassLoader()); } catch (Exception e) { throw new RuntimeException("Unable to find key class.", e); } try { this.valueClass = (Class<V>) Class.forName(valueClassName, true, Thread.currentThread().getContextClassLoader()); } catch (Exception e) { throw new RuntimeException("Unable to find value class.", e); } }
From source file:org.globus.examples.services.filebuy.seller.impl.FileResource.java
public void load(ResourceKey key) throws ResourceException { /* Try to retrieve the persisted resource from disk */ File file = getKeyAsFile(key.getValue()); /*/*from w w w .ja v a 2s . c o m*/ * If the file does not exist, no resource with that key was ever * persisted */ if (!file.exists()) { throw new NoSuchResourceException(); } /* * We try to initialize the resource. This places default values in the * RPs. We still have to load the values of the RPs from disk */ try { initialize(key.getValue()); } catch (Exception e) { throw new ResourceException("Failed to initialize resource", e); } /* Now, we open the resource file and load the values */ logger.info("Attempting to load resource " + key.getValue()); /* We will use this to read from the file */ FileInputStream fis = null; /* We will store the RPs in these variables */ String name; String location; float price; try { /* Open the file */ fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis); /* Read the RPs */ price = ois.readFloat(); name = ois.readUTF(); location = ois.readUTF(); logger.info("Successfully loaded resource with Name=" + name); /* Assign the RPs to the resource class's attributes */ setName(name); setLocation(location); setPrice(price); } catch (Exception e) { throw new ResourceException("Failed to load resource", e); } finally { /* Make sure we clean up, whether the load succeeds or not */ if (fis != null) { try { fis.close(); } catch (Exception ee) { } } } }
From source file:org.mrgeo.hdfs.vector.shp.ShapefileReader.java
@SuppressFBWarnings(value = { "WEAK_FILENAMEUTILS", "PATH_TRAVERSAL_IN" }, justification = "Correctly filtered parameters") private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { fileName = in.readUTF(); source = Source.values()[in.readInt()]; if (source == Source.FILE) { File f = new File(FilenameUtils.getFullPath(fileName), FilenameUtils.getName(fileName)); if (f.exists()) { load(fileName);/*from w ww .j a v a 2 s. c o m*/ } } else { if (HadoopFileUtils.exists(fileName)) { load(new Path(fileName)); } } }
From source file:com.hipu.bdb.util.UURI.java
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { parseUriReference(stream.readUTF(), true); }
From source file:com.izforge.izpack.installer.multiunpacker.MultiVolumeUnpacker.java
/** * Invoked prior to unpacking.//from ww w.j ava 2 s. c om * <p/> * This notifies the {@link ProgressListener}, and any registered {@link InstallerListener listeners}. * * @param packs the packs to unpack * @throws IzPackException for any error */ @Override protected void preUnpack(List<Pack> packs) { super.preUnpack(packs); InputStream in = null; ObjectInputStream objectIn = null; try { // get volume metadata in = getResources().getInputStream(VOLUMES_INFO); objectIn = new ObjectInputStream(in); int volumeCount = objectIn.readInt(); String volumeName = objectIn.readUTF(); logger.fine("Reading from " + volumeCount + " volumes with basename " + volumeName + " "); String mediaPath = getInstallData().getMediaPath(); if ((mediaPath == null) || (mediaPath.length() == 0)) { mediaPath = getDefaultMediaPath(); } logger.fine("Using mediaDirectory = " + mediaPath); File volume = new File(mediaPath, volumeName); if (!volume.exists()) { volume = locator.getVolume(volume.getAbsolutePath(), false); } volumes = new FileSpanningInputStream(volume, volumeCount); volumes.setLocator(locator); } catch (IOException exception) { throw new InstallerException(exception); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(objectIn); } }
From source file:org.seasar.mayaa.impl.engine.processor.TemplateProcessorSupport.java
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject();//from ww w.j a v a2s . co m String originalNodeID = in.readUTF(); String processorUniqueID = in.readUTF(); QName qName = QNameImpl.getInstance(URIImpl.getInstance(in.readUTF()), in.readUTF()); LibraryManager libraryManager = ProviderUtil.getLibraryManager(); setProcessorDefinition(libraryManager.getProcessorDefinition(qName)); String injectedNodeID = in.readUTF(); NodeResolveListener listener = new TemplateProcessorSupportOriginalNodeListener(this); findNodeResolver().registResolveNodeListener(originalNodeID, listener); if (UNIQUENESS_MARK.equals(injectedNodeID)) { _injectedNode = (SpecificationNode) in.readObject(); } else { listener = new TemplateProcessorSupportInjectedNodeListener(this); findNodeResolver().registResolveNodeListener(injectedNodeID, listener); } ProcessorReferenceResolver resolver = findProcessorResolver(); resolver.processorLoaded(processorUniqueID, this); // readResolve?extends?????????????? if (_children != null) { for (int i = _children.size() - 1; i >= 0; i--) { ProcessorTreeWalker child = (ProcessorTreeWalker) _children.get(i); child.setParentProcessor(this); } } LOG.debug("templateProcessorSupport loaded"); }
From source file:org.spout.api.geo.discrete.Point.java
private void readObject(java.io.ObjectInputStream in) throws IOException { float x = in.readFloat(); float y = in.readFloat(); float z = in.readFloat(); String world = in.readUTF(); World w = Spout.getEngine().getWorld(world); try {/*from www .j a va2s. co m*/ Field field; field = Vector3.class.getDeclaredField("x"); field.setAccessible(true); field.set(this, x); field = Vector3.class.getDeclaredField("y"); field.setAccessible(true); field.set(this, y); field = Vector3.class.getDeclaredField("z"); field.setAccessible(true); field.set(this, z); field = Point.class.getDeclaredField("world"); field.setAccessible(true); field.set(this, w); } catch (Exception e) { if (Spout.debugMode()) { e.printStackTrace(); } } }
From source file:edu.umass.cs.msocket.common.policies.GeoLoadProxyPolicy.java
/** * @throws Exception if a GNS error occurs * @see edu.umass.cs.msocket.common.policies.ProxySelectionPolicy#getNewProxy() *//*w w w. ja v a 2s . c o m*/ @Override public List<InetSocketAddress> getNewProxy() throws Exception { // Lookup for active location service GUIDs final UniversalGnsClient gnsClient = gnsCredentials.getGnsClient(); final GuidEntry guidEntry = gnsCredentials.getGuidEntry(); JSONArray guids; try { guids = gnsClient.fieldRead(proxyGroupName, GnsConstants.ACTIVE_LOCATION_FIELD, guidEntry); } catch (Exception e) { throw new GnsException("Could not find active location services (" + e + ")"); } // Try every location proxy in the list until one works for (int i = 0; i < guids.length(); i++) { // Retrieve the location service IP and connect to it String locationGuid = guids.getString(i); String locationIP = gnsClient.fieldRead(locationGuid, GnsConstants.LOCATION_SERVICE_IP, guidEntry) .getString(0); logger.fine("Contacting location service " + locationIP + " to request " + numProxies + " proxies"); // Location IP is stored as host:port StringTokenizer st = new StringTokenizer(locationIP, ":"); try { // Protocol is send the number of desired proxies and receive strings // containing proxy IP:port Socket s = new Socket(st.nextToken(), Integer.parseInt(st.nextToken())); ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream()); ObjectInputStream ois = new ObjectInputStream(s.getInputStream()); oos.writeInt(numProxies); oos.flush(); List<InetSocketAddress> result = new LinkedList<InetSocketAddress>(); while (!s.isClosed() && result.size() < numProxies) { String proxyIP = ois.readUTF(); StringTokenizer stp = new StringTokenizer(proxyIP, ":"); result.add(new InetSocketAddress(stp.nextToken(), Integer.parseInt(stp.nextToken()))); } if (!s.isClosed()) // We receive all the proxies we need, just close the // socket s.close(); return result; } catch (Exception e) { logger.info("Failed to obtain proxy from location service" + locationIP + " (" + e + ")"); } } throw new GnsException("Could not find any location service to provide a geolocated proxy"); }
From source file:com.inmobi.grill.driver.hive.TestRemoteHiveDriver.java
private QueryContext readContext(byte[] bytes, GrillDriver driver) throws IOException, ClassNotFoundException { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream in = new ObjectInputStream(bais); QueryContext ctx;// w w w . j a v a 2 s .co m try { ctx = (QueryContext) in.readObject(); boolean driverAvailable = in.readBoolean(); if (driverAvailable) { String clsName = in.readUTF(); ctx.setSelectedDriver(driver); } } finally { in.close(); bais.close(); } return ctx; }