當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectInputStream.close方法代碼示例

本文整理匯總了Java中java.io.ObjectInputStream.close方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectInputStream.close方法的具體用法?Java ObjectInputStream.close怎麽用?Java ObjectInputStream.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.ObjectInputStream的用法示例。


在下文中一共展示了ObjectInputStream.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getObjectFromBlob

import java.io.ObjectInputStream; //導入方法依賴的package包/類
/**
 * <p>
 * This method should be overridden by any delegate subclasses that need
 * special handling for BLOBs. The default implementation uses standard
 * JDBC <code>java.sql.Blob</code> operations.
 * </p>
 * 
 * @param rs
 *          the result set, already queued to the correct row
 * @param colName
 *          the column name for the BLOB
 * @return the deserialized Object from the ResultSet BLOB
 * @throws ClassNotFoundException
 *           if a class found during deserialization cannot be found
 * @throws IOException
 *           if deserialization causes an error
 */
protected Object getObjectFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    Object obj = null;

    Blob blobLocator = rs.getBlob(colName);
    if (blobLocator != null && blobLocator.length() != 0) {
        InputStream binaryInput = blobLocator.getBinaryStream();

        if (null != binaryInput) {
            if (binaryInput instanceof ByteArrayInputStream
                && ((ByteArrayInputStream) binaryInput).available() == 0 ) {
                //do nothing
            } else {
                ObjectInputStream in = new ObjectInputStream(binaryInput);
                try {
                    obj = in.readObject();
                } finally {
                    in.close();
                }
            }
        }

    }
    return obj;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:43,代碼來源:StdJDBCDelegate.java

示例2: getInstance

import java.io.ObjectInputStream; //導入方法依賴的package包/類
public static Inbox getInstance()
{
	if(instance != null) return instance;
	File file = new File(InboxVariables.inboxFile);
	if(file.exists())
	{
		try
		{
			FileInputStream fin = new FileInputStream(file);
			ObjectInputStream oin = new ObjectInputStream(fin);
			instance = (Inbox)oin.readObject();
			oin.close();
			fin.close();
		}
		catch(Exception ex)
		{
			ex.printStackTrace(System.err);
		}
	}
	// if not just create a new instance
	else
	{
		instance = new Inbox();
	}
	return instance;
}
 
開發者ID:travispessetto,項目名稱:OrigamiSMTP,代碼行數:27,代碼來源:Inbox.java

示例3: loadUidList

import java.io.ObjectInputStream; //導入方法依賴的package包/類
private boolean loadUidList(File uidFile) {
    if (!uidFile.exists()) {
        return false;
    }
    try {
        ObjectInputStream is = new ObjectInputStream(new FileInputStream(uidFile));
        mFreeUid = is.readInt();
        //noinspection unchecked
        Map<String, Integer> map = (HashMap<String, Integer>) is.readObject();
        mSharedUserIdMap.putAll(map);
        is.close();
    } catch (Throwable e) {
        return false;
    }
    return true;
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:17,代碼來源:UidSystem.java

示例4: JavaSerializationPeakClusterRead

import java.io.ObjectInputStream; //導入方法依賴的package包/類
private boolean JavaSerializationPeakClusterRead() {
    if (!new File(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.ser").exists()) {
        return false;
    }
    try {
        Logger.getRootLogger().info("Reading PeakCluster serialization from file:" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.ser...");

        FileInputStream fileIn = new FileInputStream(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.ser");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        PeakClusters = (ArrayList<PeakCluster>) in.readObject();
        in.close();
        fileIn.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return false;
    }
    return true;
}
 
開發者ID:YcheCourseProject,項目名稱:DIA-Umpire-Maven,代碼行數:19,代碼來源:LCMSPeakBase.java

示例5: getObjectFromBlob

import java.io.ObjectInputStream; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 * <p>
 * Caché requires {@code java.sql.Blob} instances to be explicitly freed.
 */
@Override
protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException {
    Blob blob = rs.getBlob(colName);
    if (blob == null) {
        return null;
    } else {
        try {
            if (blob.length() == 0) {
                return null;
            } else {
                InputStream binaryInput = blob.getBinaryStream();
                if (binaryInput == null) {
                    return null;
                } else if (binaryInput instanceof ByteArrayInputStream && ((ByteArrayInputStream) binaryInput).available() == 0 ) {
                    return null;
                } else {
                    ObjectInputStream in = new ObjectInputStream(binaryInput);
                    try {
                        return in.readObject();
                    } finally {
                        in.close();
                    }
                }
            }
        } finally {
            blob.free();
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:35,代碼來源:CacheDelegate.java

示例6: deserializeBlock

import java.io.ObjectInputStream; //導入方法依賴的package包/類
/**
 * Thread method that deserializes the given range of array indices.
 *
 * @param blockId The id of the array block being deserialized.
 */
private void deserializeBlock(int blockId) {
    logger.info(String.format("Deserializing block %s of %s", blockId, getArrayName()));
    long blockBeginTimeInNano = System.nanoTime();
    try {
        ObjectInputStream objectInputStream = IO.constructObjectInputStream(
            SerDeUtils.getArrayBlockFilePath(directoryPath, getClassName(), getArrayName(),
                blockId));
        int startIndexOfBlock = objectInputStream.readInt();
        int endIndexOfBlock = objectInputStream.readInt();
        for (int i = startIndexOfBlock; i <= endIndexOfBlock; i++) {
            deserializeArrayCell(objectInputStream, i);
        }
        objectInputStream.close();
        logger.info(String.format("%s block %s (from %s to %s) of %s deserialized in %.3f ms.",
            getArrayName(), blockId, startIndexOfBlock, endIndexOfBlock, getClassName(),
            IO.getElapsedTimeInMillis(blockBeginTimeInNano)));
    } catch (IOException | ClassNotFoundException e) {
        logger.error(String.format("Error deserializing block %s of %s", blockId,
            getArrayName()), e);
        throw new SerializationDeserializationException("Error in deserialization");
    }
}
 
開發者ID:graphflow,項目名稱:graphflow,代碼行數:28,代碼來源:ParallelArraySerDeUtils.java

示例7: nullSafeGetInternal

import java.io.ObjectInputStream; //導入方法依賴的package包/類
@Override
protected Object nullSafeGetInternal(
		ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
		throws SQLException, IOException, HibernateException {

	InputStream is = lobHandler.getBlobAsBinaryStream(rs, names[0]);
	if (is != null) {
		ObjectInputStream ois = new ObjectInputStream(is);
		try {
			return ois.readObject();
		}
		catch (ClassNotFoundException ex) {
			throw new HibernateException("Could not deserialize BLOB contents", ex);
		}
		finally {
			ois.close();
		}
	}
	else {
		return null;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:BlobSerializableType.java

示例8: load

import java.io.ObjectInputStream; //導入方法依賴的package包/類
public static StatisticalSummary load(String path) {
	try {
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path));
		StatisticalSummary ss = (StatisticalSummary) ois.readObject();
		ois.close();
		return ss;
	} catch (Exception e) {
		System.out.println(e);
		return null;
	}
}
 
開發者ID:CognitiveModeling,項目名稱:BrainControl,代碼行數:12,代碼來源:StatisticalSummary.java

示例9: readFromFile

import java.io.ObjectInputStream; //導入方法依賴的package包/類
private void readFromFile(String fn) throws IOException, ClassNotFoundException {
    File file = new File(fn);
    FileInputStream f = new FileInputStream(file);
    ObjectInputStream s = new ObjectInputStream(f);
    MinterestMap = (HashMap<String, String>) s.readObject();
    MinterestResultMap = (HashMap<String, Set<String>>) s.readObject();
    rMinterestMap = (HashMap<String, String>) s.readObject();
    rMinterestResultMap = (HashMap<String, Set<String>>) s.readObject();
    FinterestMap = (HashMap<String, String>) s.readObject();
    FinterestResultMap = (HashMap<String, Set<String>>) s.readObject();
    s.close();
}
 
開發者ID:Alexandre-Bartel,項目名稱:permission-map,代碼行數:13,代碼來源:FindTargetMethod.java

示例10: hent

import java.io.ObjectInputStream; //導入方法依賴的package包/類
public static Object hent(String filnavn) throws Exception {
  FileInputStream datastrøm = new FileInputStream(filnavn);
  ObjectInputStream objektstrøm = new ObjectInputStream(datastrøm);
  Object obj = objektstrøm.readObject();
  objektstrøm.close();
  return obj;
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:8,代碼來源:Serialisering.java

示例11: serDeser

import java.io.ObjectInputStream; //導入方法依賴的package包/類
private static HashSet<Integer> serDeser(HashSet<Integer> hashSet) throws IOException, ClassNotFoundException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(hashSet);
    oos.flush();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bais);
    HashSet<Integer> result = (HashSet<Integer>)ois.readObject();

    oos.close();
    ois.close();

    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:Serialization.java

示例12: getObjectDeserializingIfNeeded

import java.io.ObjectInputStream; //導入方法依賴的package包/類
private Object getObjectDeserializingIfNeeded(int columnIndex) throws SQLException {
    final Field field = this.fields[columnIndex - 1];

    if (field.isBinary() || field.isBlob()) {
        byte[] data = getBytes(columnIndex);

        if (this.connection.getAutoDeserialize()) {
            Object obj = data;

            if ((data != null) && (data.length >= 2)) {
                if ((data[0] == -84) && (data[1] == -19)) {
                    // Serialized object?
                    try {
                        ByteArrayInputStream bytesIn = new ByteArrayInputStream(data);
                        ObjectInputStream objIn = new ObjectInputStream(bytesIn);
                        obj = objIn.readObject();
                        objIn.close();
                        bytesIn.close();
                    } catch (ClassNotFoundException cnfe) {
                        throw SQLError.createSQLException(Messages.getString("ResultSet.Class_not_found___91") + cnfe.toString()
                                + Messages.getString("ResultSet._while_reading_serialized_object_92"), getExceptionInterceptor());
                    } catch (IOException ex) {
                        obj = data; // not serialized?
                    }
                } else {
                    return getString(columnIndex);
                }
            }

            return obj;
        }

        return data;
    }

    return getBytes(columnIndex);
}
 
開發者ID:Jugendhackt,項目名稱:OpenVertretung,代碼行數:38,代碼來源:ResultSetImpl.java

示例13: loadHistogramFromFile

import java.io.ObjectInputStream; //導入方法依賴的package包/類
public void loadHistogramFromFile(File file) {
    try {
        FileInputStream fis = new FileInputStream(file);
        ObjectInputStream ois = new ObjectInputStream(fis);
        setHistmax((Integer) ois.readObject());
        histogram = (int[][]) ois.readObject();
        bitmap=(boolean[][]) ois.readObject();
        setThreshold(ois.readFloat());
        numX=0; numY=0;
        if(histogram!=null){
            numX=histogram.length;
            if(histogram[0]!=null){
                numY=histogram[0].length;
            }
        }
        numPix = numX * numY;
        computeTotalSum(); // in case loaded from file
        computeErodedBitmap(); // in case not stored
        ois.close();
        fis.close();
        log.info("histogram loaded from (usually host/java) file " + file.getPath() + "; histmax=" + histmax);
        setFilePath(file.getPath());

    } catch (Exception e) {
        log.info("couldn't load histogram from file " + file + ": " + e.toString());
    }
}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:28,代碼來源:Histogram2DFilter.java

示例14: testLargeString

import java.io.ObjectInputStream; //導入方法依賴的package包/類
/**
 * 
 * Test write/read of a large string (> 64Kb)
 *
 * @throws Exception
 */
@Test
public void testLargeString() throws Exception
{
    ObjectOutputStream dos = new ObjectOutputStream( fos );
    ObjectInputStream dis = new ObjectInputStream( fis );
    char[] fill = new char[196622]; // 65535 * 3 + 17
    Arrays.fill( fill, '\u00fc' ); // German &&uuml
    String testString = new String( fill );
    Unicode.writeUTF( dos, testString );
    dos.flush();
    dos.close();
    assertEquals( testString, Unicode.readUTF( dis ) );
    dis.close();
}
 
開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:21,代碼來源:UnicodeTest.java

示例15: readInContext

import java.io.ObjectInputStream; //導入方法依賴的package包/類
public NamingContextImpl readInContext(String objKey)
{
    NamingContextImpl context = (NamingContextImpl) contexts.get(objKey);
    if( context != null )
    {
            // Returning Context from Cache
            return context;
    }

    File contextFile = new File(logDir, objKey);
    if (contextFile.exists()) {
        try {
            FileInputStream fis = new FileInputStream(contextFile);
            ObjectInputStream ois = new ObjectInputStream(fis);
            context = (NamingContextImpl) ois.readObject();
            context.setORB( orb );
            context.setServantManagerImpl( this );
            context.setRootNameService( theNameService );
            ois.close();
        } catch (Exception ex) {
        }
    }

    if (context != null)
    {
            contexts.put(objKey, context);
    }
    return context;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:ServantManagerImpl.java


注:本文中的java.io.ObjectInputStream.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。