/*
(non-Javadoc)

@see com.ibm.ws.objectManager.AbstractSingleFileObjectStore#writeFreeSpace()
548692
final void writeFreeSpace()
                    throws ObjectManagerException {
        final String methodName = "writeFreeSpace";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        methodName);

        // Write the free space map to disk.
        byteArrayOutputStream.reset();
        java.io.DataOutputStream dataOutputStream = new java.io.DataOutputStream(byteArrayOutputStream);
        long freeSpaceByteAddress = freeSpaceStoreArea.byteAddress;
        try {
            FreeSpace freeSpace = freeSpaceByAddressHead;
            while (freeSpace != null) {
                dataOutputStream.writeLong(freeSpace.address);
                dataOutputStream.writeLong(freeSpace.length);
                freeSpace = freeSpace.next;
            } // for freeSpaceByAddress...
            dataOutputStream.flush();
            byteArrayOutputStream.flush();
        } catch (java.io.IOException exception) {
            // No FFDC Code Needed.
            ObjectManager.ffdc.processException(this, cclass, "flush", exception, "1:724:1.35");

            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this,
                           cclass,
                           "flush");
            throw new PermanentIOException(this,
                                           exception);
        } // catch.

        writeBuffer(byteArrayOutputStream.getBuffer(),
                    0,
                    byteArrayOutputStream.getCount(),
                    freeSpaceByteAddress);

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       methodName);
    }
246653
@Override
    public void setTopicSpace(String tSpace) throws JMSException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setTopicSpace", tSpace);
        setDestName(tSpace);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setTopicSpace");
    }
1207420
protected void saveSSpace(SemanticSpace sspace, File outputFile)
            throws IOException{
        BasisMapping<String, String> savedTerms = new StringBasisMapping();
        for (String term : sspace.getWords())
            savedTerms.getDimension(term);

        ObjectOutputStream ouStream = new ObjectOutputStream(
                new FileOutputStream(outputFile));
        ouStream.writeObject(savedTerms);
        ouStream.close();
    }
849463
@Override
    public void outputNamespaceDeclarations(Writer w) throws IOException
    {
        String[] ns = mNamespaces;
        for (int i = mFirstLocalNs, len = mNsLength; i < len; i += 2) {
            w.write(' ');
            w.write(XMLConstants.XMLNS_ATTRIBUTE);
            String prefix = ns[i];
            if (prefix != null && prefix.length() > 0) {
                w.write(':');
                w.write(prefix);
            }
            w.write("=\"");
            w.write(ns[i+1]);
            w.write('"');
        }
    }
313563
def free_address
      if @first_space == 0
        # There is currently no free entry. Create a new reserved entry at the
        # end of the file.
        begin
          offset = @f.size
          @f.seek(offset)
          write_n_bytes([1] + ::Array.new(@entry_bytes, 0))
          write_header
          return offset_to_address(offset)
        rescue IOError => e
          PEROBS.log.fatal "Cannot create reserved space at #{@first_space} " +
            "in EquiBlobsFile #{@file_name}: #{e.message}"
        end
      else
        begin
          free_space_address = offset_to_address(@first_space)
          @f.seek(@first_space)
          marker = read_char
          @first_space = read_unsigned_int
          unless marker == 0
            PEROBS.log.fatal "Free space list of EquiBlobsFile #{@file_name} " +
              "points to non-empty entry at address #{@first_space}"
          end
          # Mark entry as reserved by setting the mark byte to 1.
          @f.seek(-(1 + 8), IO::SEEK_CUR)
          write_char(1)

          # Update the file header
          @total_spaces -= 1
          write_header
          return free_space_address
        rescue IOError => e
          PEROBS.log.fatal "Cannot mark reserved space at " +
            "#{free_space_address} in EquiBlobsFile #{@file_name}: " +
            "#{e.message}"
        end
      end
    end
830655
private void checkFreeDiskSpace(List<File> inputFiles) {
    //Check for free space
    long usableSpace = 0;
    long totalSize = 0;
    for (File f : inputFiles) {
      if (f.exists()) {
        totalSize += f.length();
        usableSpace = f.getUsableSpace();
      }
    }
    LOGGER.log(Level.INFO, "Total expected store size is {0} Mb",
        new DecimalFormat("#,##0.0").format(totalSize / (1024 * 1024)));
    LOGGER.log(Level.INFO, "Usable free space on the system is {0} Mb",
        new DecimalFormat("#,##0.0").format(usableSpace / (1024 * 1024)));
    if (totalSize / (double) usableSpace >= 0.66) {
      throw new RuntimeException("Aborting because there isn' enough free disk space");
    }
  }
826913
private void setFileSpaceLeft()
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass,
                        "setFileSpaceLeft",
                        new Object[] { new Long(fileLogHeader.fileSize), new Long(fileLogHeader.startByteAddress),
                                      new Long(filePosition) }
                            );

        // Assume we have wrapped around the end of the file, the space left is between the current
        // file position and the start of the log file.
        long newFileSpaceLeft = fileLogHeader.startByteAddress - filePosition;
        if (newFileSpaceLeft <= 0) // If we have not wrapped. 
            newFileSpaceLeft = newFileSpaceLeft + fileLogHeader.fileSize - FileLogHeader.headerLength * 2;
        fileSpaceLeft = newFileSpaceLeft;

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       "setFileSpaceLeft",
                       new Object[] { new Long(fileSpaceLeft) });
    }
1259232
public void writeEmptyElement(String namespaceURI, String localName) throws Exception {
		startTag(namespaceURI, localName);
		endTag(namespaceURI, localName);

	}
78819
@Override
    public void writeNamespace(String prefix, String nsURI) throws XMLStreamException
    {
        if (prefix == null || prefix.length() == 0) {
            writeDefaultNamespace(nsURI);
            return;
        }
        if (!mNsAware) {
            throwOutputError("Can not write namespaces with non-namespace writer.");
        }
        outputAttribute(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns", prefix, nsURI);
        mCurrElem.addPrefix(prefix, nsURI);
    }
1150076
private void writeObject(ObjectOutputStream s) throws IOException
  {
    if (words != null && lastWordIndex < words.length - 1) {
      // compact before serializing
      words = Arrays.copyOf(words, lastWordIndex + 1);
    }
    s.defaultWriteObject();
  }
676970
public void write(final Writer outputWriter) throws IOException {
    try (final DataInputStream keyStream = entry.getKeyStream();
         final DataInputStream valueStream = entry.getValueStream();) {
      outputWriter.write("Container: ");
      outputWriter.write(keyStream.readUTF());
      outputWriter.write("\n");
      this.writeFiles(valueStream, outputWriter);
    }
  }
399772
private boolean writeMetaData(final boolean isClean) {
		if (readOnly) {
			return true;
		}
		final WriteBuffer wbuf = storage.set(0);
		final ByteBuffer buf = wbuf.buf();
		boolean isOK = false;
		// @formatter:off
		buf
		.putInt(MAGIC_1)
		.putInt(blockSize)
		.putInt(b_order_leaf)
		.putInt(b_order_internal)
		.putInt(storageBlock)
		.putInt(rootIdx)
		.putInt(lowIdx)
		.putInt(highIdx)
		.putInt(elements)
		.putInt(height)
		.putInt(maxInternalNodes)
		.putInt(maxLeafNodes)
		.put((byte) (isClean ? 0xEA : 0x00))
		.putInt(MAGIC_2)
		.flip();
		// @formatter:on
		isOK = wbuf.save();
		if (isClean) {
			storage.sync();
		}
		try {
			if (isClean) {
				SimpleBitSet.serializeToFile(fileFreeBlocks, freeBlocks);
			} else {
				fileFreeBlocks.delete();
			}
		} catch (IOException e) {
			log.error("IOException in writeMetaData(" + isClean + ")", e);
		}
		if (log.isDebugEnabled()) {
			log.debug(this.getClass().getName() + "::writeMetaData() elements=" + elements + " rootIdx="
					+ rootIdx + " lastNodeId=" + storageBlock + " freeBlocks=" + freeBlocks.cardinality());
		}
		return isOK;
	}
520658
@Override
    public void writeExternal(ObjectOutput s) throws IOException {
        if (!removedFromLeakDetection) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                Tr.event(tc,
                         "Buffer being serialized but removeFromLeakDetection has not been called: " + this);
            }
        }

        if (oByteBuffer.isDirect()) {
            // hard code as local strings to help performance.
            // Strings are used here and and in the readObject routines
            s.writeObject("D");
        } else {
            s.writeObject("ND");
        }
        if (oByteBuffer.order() == java.nio.ByteOrder.BIG_ENDIAN) {
            s.writeObject("B");
        } else {
            s.writeObject("L");
        }

        int startPosition = oByteBuffer.position();
        int startLimit = oByteBuffer.limit();

        // set position to 0 and limit to capacity, so we can serialize
        // the entire buffer
        this.oByteBuffer.position(0);
        this.oByteBuffer.limit(this.oByteBuffer.capacity());

        if (oByteBuffer.hasArray() && oByteBuffer.arrayOffset() == 0) {
            s.writeObject(oByteBuffer.array());
        } else {
            byte[] bytes = new byte[oByteBuffer.limit()];
            this.oByteBuffer.get(bytes);
            s.writeObject(bytes);
        }

        this.oByteBuffer.position(startPosition);
        this.oByteBuffer.limit(startLimit);

        s.writeObject(Integer.toString(startPosition));
        s.writeObject(Integer.toString(startLimit));

        if (this.readOnly) {
            s.writeObject("R");
        } else {
            s.writeObject("RW");
        }
    }
593946
final void writeHeader()
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        "writeHeader");

        byteArrayOutputStream.reset();
        java.io.DataOutputStream dataOutputStream = new java.io.DataOutputStream(byteArrayOutputStream);

        // Write the header.
        try {
            dataOutputStream.writeInt(version);
            dataOutputStream.writeChars(signature);
            dataOutputStream.writeLong(objectStoreIdentifier);
            dataOutputStream.writeLong(((Directory.Node) directory.root).byteAddress);
            dataOutputStream.writeLong(((Directory.Node) directory.root).length);
            dataOutputStream.writeInt(directory.getMinimumNodeSize());
            if (freeSpaceStoreArea == null) {
                dataOutputStream.writeLong(0);
                dataOutputStream.writeLong(0);
            } else {
                dataOutputStream.writeLong(freeSpaceStoreArea.byteAddress);
                dataOutputStream.writeLong(freeSpaceStoreArea.length);
            }
            dataOutputStream.writeLong((long) freeSpaceByLength.size());
            dataOutputStream.writeLong(sequenceNumber);
            dataOutputStream.writeLong(storeFileSizeUsed);
            dataOutputStream.writeLong(minimumStoreFileSize);
            dataOutputStream.writeLong(maximumStoreFileSize);
            dataOutputStream.writeInt(cachedManagedObjectsSize);

            dataOutputStream.flush();
            byteArrayOutputStream.flush();
        } catch (java.io.IOException exception) {
            // No FFDC Code Needed.
            ObjectManager.ffdc.processException(this, cclass, "writeHeader", exception, "1:836:1.35");

            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this,
                           cclass,
                           "flush");
            throw new PermanentIOException(this,
                                           exception);
        } // catch.

        byte[] buffer = byteArrayOutputStream.getBuffer();
        int length = byteArrayOutputStream.getCount();
        writeBuffer(buffer,
                    0,
                    length,
                    0);
        // Write the header twice.
        writeBuffer(buffer,
                    0,
                    length,
                    pageSize);

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       "writeHeader"
                            );
    }
601350
@Override
    public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
	try {
	    out.writeObject(new HashMap(this));
	}
	catch (NotSerializableException nse) {
	    NotSerializableException tmp = new NotSerializableException(nse.getMessage() + ":" + entries());
	    tmp.initCause(nse);
	    throw tmp;
	}
    }
1300717
@Override
  public void write(DataOutput out) throws IOException {
    Text.writeString(out, file.toString());
    out.writeLong(start);
    out.writeLong(length);
  }
1257541
protected int getFreeSpace()
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "getFreeSpace", this);

        final int freeBytes = _activeFile.freeBytes();

        if (tc.isEntryEnabled())
            Tr.exit(tc, "getFreeSpace", freeBytes);

        return freeBytes;
    }