Writes the inventory to the specified file. See also {@link #read(File)}.
@param prefix the file prefix for a temporary backup file
@param catalog the file to write to
@throws IOException if the file could not be updated
351840
void write(String prefix, File catalog) throws IOException {
		File backup = File.createTempFile(prefix, null, catalog.getParentFile());
		if (catalog.exists()) {
			// Create a copy of the current state
			Files.copy(catalog.toPath(), backup.toPath(), StandardCopyOption.REPLACE_EXISTING);
		}

		// Update the file
		try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(catalog))) {
			oos.writeObject(this);
			backup.delete();
		} catch (IOException e) {
			try {
				Files.move(backup.toPath(), catalog.toPath(), StandardCopyOption.ATOMIC_MOVE);
			} catch (IOException e2) {
				logger.log(Level.INFO, "A backup has been saved at: " + backup, e2);
			}
			throw new IOException("Failed to update file: " + catalog, e);
		}
	}
700314
private void registerPrefix(String field, String prefix,
      IndexOutput outPrefix) throws IOException {
    if (!prefixReferenceIndex.containsKey(field)) {
      prefixReferenceIndex.put(field, new HashMap<String, Long>());
      prefixIdIndex.put(field, new HashMap<String, Integer>());
    }
    if (!prefixReferenceIndex.get(field).containsKey(prefix)) {
      int id = 1 + prefixReferenceIndex.get(field).size();
      prefixReferenceIndex.get(field).put(prefix, outPrefix.getFilePointer());
      prefixIdIndex.get(field).put(prefix, id);
      outPrefix.writeString(prefix);
    }
  }
634144
@SuppressWarnings("unused")
	public void setPrefix(String prefix, String namespace) throws IOException {
		if (startTagIncomplete)
			closeStartTag();
		// assert prefix != null;
		// assert namespace != null;
		if (prefix == null) {
			prefix = "";
		}
		if (!namesInterned) {
			prefix = prefix.intern(); // will throw NPE if prefix==null
		} else if (checkNamesInterned) {
			checkInterning(prefix);
		} else if (prefix == null) {
			throw new IllegalArgumentException("prefix must be not null" + getLocation());
		}

		// check that prefix is not duplicated ...
		for (int i = elNamespaceCount[depth]; i < namespaceEnd; i++) {
			if (prefix == namespacePrefix[i]) {
				throw new IllegalStateException("duplicated prefix " + printable(prefix) + getLocation());
			}
		}

		if (!namesInterned) {
			namespace = namespace.intern();
		} else if (checkNamesInterned) {
			checkInterning(namespace);
		} else if (namespace == null) {
			throw new IllegalArgumentException("namespace must be not null" + getLocation());
		}

		if (namespaceEnd >= namespacePrefix.length) {
			ensureNamespacesCapacity();
		}
		namespacePrefix[namespaceEnd] = prefix;
		namespaceUri[namespaceEnd] = namespace;
		++namespaceEnd;
		setPrefixCalled = true;
	}
897688
public static File writeToTempFile(ByteBuffer byteBuffer, String prefix, String suffix) throws IOException {
        File tmpOutputFile = null;

        try (RandomAccessFile outputRaf = new RandomAccessFile(tmpOutputFile, "rw")) {
            // Create temporary file
            tmpOutputFile = File.createTempFile(prefix, "." + suffix);
            FileChannel outputChannel = outputRaf.getChannel();

            outputChannel.write(byteBuffer);

        } catch (IOException ioe) {
            String info = "Failed to write to temporary file: " + ioe.getMessage();
            throw new IOException(info, ioe);
        }
        return tmpOutputFile;
    }
252789
public void writeNestedLibrary(String destination, Library library)
			throws IOException {
		File file = library.getFile();
		JarArchiveEntry entry = new JarArchiveEntry(destination + library.getName());
		entry.setTime(getNestedLibraryTime(file));
		new CrcAndSize(file).setupStoredEntry(entry);
		writeEntry(entry, new InputStreamEntryWriter(new FileInputStream(file), true),
				new LibraryUnpackHandler(library));
	}
114592
public void write(final File folder) throws IOException {
    try (final DataInputStream keyStream = entry.getKeyStream();
         final DataInputStream valueStream = entry.getValueStream();) {
      final String containerId = keyStream.readUTF();
      try (final Writer outputWriter = new OutputStreamWriter(
          new FileOutputStream(new File(folder, containerId + ".txt")), StandardCharsets.UTF_8)) {
        this.writeFiles(valueStream, outputWriter);
      }
    }
  }
1181418
protected void deleteEntryFiles() throws IOException {
    File[] files = getDirectory().listFiles();
    if(files == null) return;
    
    String prefix = getEntryLogPrefix();
    String suffix = getEntryLogSuffix();
    
    for (File file : files) {
      String fileName = file.getName();
      if (fileName.startsWith(prefix) && fileName.endsWith(suffix)) {
        if (file.delete()) {
          _log.info("file " + file.getAbsolutePath() + " deleted");
        } else {
          _log.warn("file " + file.getAbsolutePath() + " not deleted");
        }
      }
    }
  }
1056196
@Override
  void write(ByteCodeWriter out)
    throws IOException
  {
    out.write(ConstantPool.CP_METHODHANDLE);
    out.write(_type.getCode());
    out.writeShort(_entry.getIndex());
  }
172103
public File createDirectorySync(String prefix) throws IOException {
		Path path = Files.createTempDirectory(tempDir.toPath(), this.prefix + prefix);
		File dir = path.toFile();
		/*
		app.toClose(new Closeable() {
			@Override
			public void close() {
				new RemoveDirectoryTask(dir, null, 0, null, Task.PRIORITY_NORMAL, false).start();
			}
		});*/
		return dir;
	}
596466
def writeXYCatalog(self,filename):
        
        if self.xypos is None:
            warnstr = textutil.textbox(
                'WARNING: \n    No X,Y source catalog to write to file. ')
            for line in warnstr.split('\n'):
                log.warning(line)
            print(warnstr)
            return

        f = open(filename,'w')
        f.write("# Source catalog derived for %s\n"%self.wcs.filename)
        f.write("# Columns: \n")
        if self.use_sharp_round:
            f.write('#    X      Y         Flux       ID      Sharp       Round1       Round2\n')
        else:
            f.write('#    X      Y         Flux       ID\n')
        f.write('#   (%s)   (%s)\n'%(self.in_units,self.in_units))

        for row in range(len(self.xypos[0])):
            for i in range(len(self.xypos)):
                f.write("%g  "%(self.xypos[i][row]))
            f.write("\n")

        f.close()
620508
private void outputIndexTermEndElement(final IndexTerm term, final XMLStreamWriter serializer, final boolean indexsee) throws XMLStreamException {
        if (indexsee){
            if (term.getTermPrefix() != null) {
                serializer.writeEndElement(); // see
                inIndexsee = false;
            } else if (inIndexsee) {
                // NOOP
            } else {
                serializer.writeEndElement(); // entry
            }
        } else {
            serializer.writeEndElement(); // entry
        }
    }
534294
public static <T> void writeListTo(MessagePacker packer, List<T> messages,
            Schema<T> schema, boolean numeric) throws IOException
    {
        MsgpackGenerator generator = new MsgpackGenerator(numeric);
        MsgpackOutput output = new MsgpackOutput(generator, schema);

        for (T m : messages)
        {
            schema.writeTo(output, m);
            generator.writeTo(packer);
            generator.reset();
        }

    }
1305586
public void setPrefix(String prefix) {
		this.prefix = prefix;
		if (this.prefix != null && this.prefix.isEmpty())
			this.prefix = null;
	}
590159
public void writeAll() throws IOException {
    this.layoutVersion = FSConstants.LAYOUT_VERSION;
    for (Iterator<StorageDirectory> it = storageDirs.iterator(); it.hasNext();) {
      it.next().write();
    }
  }
64639
void copyIndex(final AbstractIndex index) throws IOException
   {
      // commit changes to directory on other index.
      index.commit(true);
      // simply copy over the files
      byte[] buffer = new byte[1024];
      Directory dir = index.getDirectory();
      Directory dest = getDirectory();
      String[] files = dir.listAll();
      for (int i = 0; i < files.length; i++)
      {
         IndexInput in = dir.openInput(files[i]);
         try
         {
            IndexOutput out = dest.createOutput(files[i]);
            try
            {
               long remaining = in.length();
               while (remaining > 0)
               {
                  int num = (int)Math.min(remaining, buffer.length);
                  in.readBytes(buffer, 0, num);
                  out.writeBytes(buffer, num);
                  remaining -= num;
               }
            }
            finally
            {
               out.close();
            }
         }
         finally
         {
            in.close();
         }
      }
   }
1222564
public static <T> void writeTo(MessageBufferOutput out, T message, Schema<T> schema, boolean numeric)
            throws IOException
    {

        MessagePacker packer = MessagePack.newDefaultPacker(out);

        try
        {
            writeTo(packer, message, schema, numeric);
        }
        finally
        {
            packer.flush();
        }
    }
1178577
public void addPrefixesFile(String filename) throws IOException {
    try (Reader r = Files.newBufferedReader(Paths.get(filename), StandardCharsets.UTF_8)) {
      addPrefixProperties(r);
    }
  }