Converts an object to an XML file.

@param object The object to convert.
@param fileName  The filename where to save it to.
@throws FileNotFoundException On error.
18526
public static void objectToXML(Object object, String fileName) throws FileNotFoundException {
		FileOutputStream fo = new FileOutputStream(fileName);
		XMLEncoder encoder = new XMLEncoder(fo);
		encoder.writeObject(object);
		encoder.close();
	}
1051230
public static File writeObjectToFileNoExceptions(Object o, String filename) {
    File file = null;
    ObjectOutputStream oos = null;
    try {
      file = new File(filename);
      // file.createNewFile(); // cdm may 2005: does nothing needed
      oos = new ObjectOutputStream(new BufferedOutputStream(
          new GZIPOutputStream(new FileOutputStream(file))));
      oos.writeObject(o);
      oos.close();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      closeIgnoringExceptions(oos);
    }
    return file;
  }
609254
public static Object loadXMLInfo(String filename) throws JAXBException {
        Object obj = null;
        JAXBContext jaxbContext = JAXBContext.newInstance(CLINVAR_CONTEXT_v53);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        obj = unmarshaller.unmarshal(new File(filename));
        return obj;
    }
958301
static String getFile( String name )
        throws FileNotFoundException, IOException
    {
        StringBuilder sb = new StringBuilder();
        try ( BufferedReader bin = new BufferedReader( new FileReader( name ) ) ) {
            String line;
            while ( (line=bin.readLine()) != null )
                sb.append( line ).append( "\n" );
        }
        return sb.toString();
    }
1121145
public static <T extends Saveable> void save(@Nonnull T object) throws IOException {
        if (!BulkChange.contains(object)) {
            XmlFile file = getConfigFile(object.getClass());
            file.write(object);
            SaveableListener.fireOnChange(object, file);
        }
    }
844092
def write(filename, jobject):
    
    if isinstance(jobject, JavaObject):
        jobject = jobject.jobject
    javabridge.static_call(
        "Lweka/core/SerializationHelper;", "write",
        "(Ljava/lang/String;Ljava/lang/Object;)V",
        filename, jobject)
322086
private ClientProperties onParseXML(String propertyFileName, PersistenceUnitMetadata puMetadata)
    {
        InputStream inStream = puMetadata.getClassLoader().getResourceAsStream(propertyFileName);
        if (inStream == null)
        {
            propertyFileName = KunderaCoreUtils.resolvePath(propertyFileName);
            try
            {
                inStream = new FileInputStream(new File(propertyFileName));
            }
            catch (FileNotFoundException e)
            {
                log.warn("File {} not found, Caused by ", propertyFileName);
                return null;
            }

        }

        if (inStream != null)
        {
            xStream = getXStreamObject();
            Object o = xStream.fromXML(inStream);
            return (ClientProperties) o;
        }

        return null;
    }
79894
@Nonnull
  @SuppressFBWarnings ("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
  @MustBeLocked (ELockType.WRITE)
  private ESuccess _writeToFile ()
  {
    // Build the filename to write to
    final String sFilename = m_aFilenameProvider.get ();
    if (sFilename == null)
    {
      // We're not operating on a file! Required for testing
      if (LOGGER.isWarnEnabled ())
        LOGGER.warn ("The DAO of class " + getClass ().getName () + " cannot write to a file");
      return ESuccess.FAILURE;
    }

    // Check for a filename change before writing
    if (!sFilename.equals (m_sPreviousFilename))
    {
      onFilenameChange (m_sPreviousFilename, sFilename);
      m_sPreviousFilename = sFilename;
    }

    if (isDebugLogging ())
      if (LOGGER.isInfoEnabled ())
        LOGGER.info ("Trying to write WAL DAO file '" + sFilename + "'");

    File aFileNew = null;
    IMicroDocument aDoc = null;
    final String sFilenameNew = _getFilenameNew (sFilename);
    final String sFilenamePrev = _getFilenamePrev (sFilename);
    try
    {
      // Get the file handle
      aFileNew = getSafeFile (sFilenameNew, EMode.WRITE);

      m_aStatsCounterWriteTotal.increment ();
      final StopWatch aSW = StopWatch.createdStarted ();

      // Create XML document to write
      aDoc = createWriteData ();
      if (aDoc == null)
        throw new DAOException ("Failed to create data to write to file");

      // Generic modification
      modifyWriteData (aDoc);

      // Get the output stream
      final OutputStream aOS = FileHelper.getOutputStream (aFileNew);
      if (aOS == null)
      {
        // Happens, when another application has the file open!
        // Logger warning already emitted
        throw new DAOException ("Failed to open output stream for '" + aFileNew.getAbsolutePath () + "'");
      }

      // Write to file (closes the OS)
      final IXMLWriterSettings aXWS = getXMLWriterSettings ();
      if (MicroWriter.writeToStream (aDoc, aOS, aXWS).isFailure ())
        throw new DAOException ("Failed to write DAO XML data to file");

      // Rename existing file to old
      FileIOError aIOError;
      boolean bRenamedToPrev = false;
      if (m_aIO.existsFile (sFilename))
      {
        aIOError = m_aIO.renameFile (sFilename, sFilenamePrev);
        bRenamedToPrev = true;
      }
      else
        aIOError = new FileIOError (EFileIOOperation.RENAME_FILE, EFileIOErrorCode.NO_ERROR);
      if (aIOError.isSuccess ())
      {
        // Rename new file to final
        aIOError = m_aIO.renameFile (sFilenameNew, sFilename);
        if (aIOError.isSuccess ())
        {
          // Finally delete old file
          aIOError = m_aIO.deleteFileIfExisting (sFilenamePrev);
        }
        else
        {
          // 2nd rename failed
          // -> Revert original rename to stay as consistent as possible
          if (bRenamedToPrev)
            m_aIO.renameFile (sFilenamePrev, sFilename);
        }
      }
      if (aIOError.isFailure ())
        throw new IllegalStateException ("Error on rename(existing-old)/rename(new-existing)/delete(old): " + aIOError);

      // Update stats etc.
      m_aStatsCounterWriteTimer.addTime (aSW.stopAndGetMillis ());
      m_aStatsCounterWriteSuccess.increment ();
      m_nWriteCount++;
      m_aLastWriteDT = PDTFactory.getCurrentLocalDateTime ();
      return ESuccess.SUCCESS;
    }
    catch (final DAOException | RuntimeException ex)
    {
      final String sErrorFilename = aFileNew != null ? aFileNew.getAbsolutePath () : sFilename;

      if (LOGGER.isErrorEnabled ())
        LOGGER.error ("The DAO of class " +
                      getClass ().getName () +
                      " failed to write the DAO data to '" +
                      sErrorFilename +
                      "'",
                      ex);

      triggerExceptionHandlersWrite (ex, sErrorFilename, aDoc);
      m_aStatsCounterWriteExceptions.increment ();
      return ESuccess.FAILURE;
    }
  }
418188
public static byte[] objectToBytes(Object object) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream os = new ObjectOutputStream(baos);
    os.writeObject(object);
    return baos.toByteArray();
  }
178437
public Object source( String filename )
        throws FileNotFoundException, IOException, EvalError
    {
        return source( filename, globalNameSpace );
    }
1019690
public static FileNotFoundException getFileNotFoundException(
      String bucketName, String objectName) {
    checkArgument(!isNullOrEmpty(bucketName), "bucketName must not be null or empty");
    return new FileNotFoundException(
        String.format(
            "Item not found: '%s'."
                + " If you enabled STRICT generation consistency, it is possible that"
                + " the live version is still available but the intended generation is deleted.",
            StorageResourceId.createReadableString(bucketName, nullToEmpty(objectName))));
  }
1265369
protected void save(String fileName) throws Exception {
	    configuration.save(new File(fileName));
		if (isNewState()) {
		    model.moveSessionDb(fileName);
		} else {
		    if (!this.fileName.equals(fileName)) {
		        // copy file to new fileName
		        model.copySessionDb(this.fileName, fileName);
		    }
		}
	    this.fileName = fileName;
		
    	if (! Constant.isLowMemoryOptionSet()) {
			synchronized (siteTree) {
			    saveSiteTree(siteTree.getRoot());
			}
    	}
		
		model.getDb().getTableSession().update(getSessionId(), getSessionName());
	}
1273337
@GwtIncompatible("com.google.io.Files")
  public void save(String filename) throws IOException {
    Files.write(toBytes(), new File(filename));
  }
779666
public void setFile(File file) throws FileNotFoundException{
		this.setInputStream(new BufferedInputStream(new FileInputStream(file)), file.length());
		this.isUploadFile = true;
	}
1069835
public static File writeObjectToTempFileNoExceptions(Object o, String filename) {
    try {
      return writeObjectToTempFile(o, filename);
    } catch (Exception e) {
      System.err.println("Error writing object to file " + filename);
      e.printStackTrace();
      return null;
    }
  }
1153396
public File getFile(String fileName) throws IOException {
    validatePathname(fileName);

    String pathname = storageDir + separator + fileName;

    File file = new File(pathname);
    if (!file.exists()) {
      throw new FileNotFoundException(pathname);
    }
    if (!file.isFile()) {
      throw new IOException('\'' + pathname + '\'' + " is not a file");
    }
    return file;
  }
915359
public void send(Object object) {
        if (object instanceof File) {
            file((File) object);
        } else {
            send(object, getContentType());
        }
    }