/*
(non-Javadoc)
@see edu.jhu.hlt.acute.archivers.Archiver#addEntry(edu.jhu.hlt.acute.archivers.Archivable)
9129
@Override
  public void addEntry(Archivable arch) throws IOException {
    final String fn = arch.getFileName();
    TarArchiveEntry entry = new TarArchiveEntry(fn);
    byte[] cbytes = arch.getBytes();
    entry.setSize(cbytes.length);
    this.tos.putArchiveEntry(entry);
    try (ByteArrayInputStream bis = new ByteArrayInputStream(cbytes)) {
      IOUtils.copy(bis, tos);
      tos.closeArchiveEntry();
    }
  }
1219707
private void addFileStreamEntries(String kind) {
        Obligation obligation = database.getFactory().addObligation("java.io." + kind);
        database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance(Values.DOTTED_JAVA_IO_FILE + kind)),
                new ExactStringMatcher("<init>"), new RegexStringMatcher(".*"), false, ObligationPolicyDatabaseActionType.ADD,
                ObligationPolicyDatabaseEntryType.STRONG, obligation));
        database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.io." + kind)),
                new ExactStringMatcher("close"), new ExactStringMatcher("()V"), false, ObligationPolicyDatabaseActionType.DEL,
                ObligationPolicyDatabaseEntryType.STRONG, obligation));
    }
1004032
public void add(Historizable historizable) {
    LOGGER.debug("+++ entering HistorizableList.add +++");
    synchronized (historizables) {
      if (historizables.size() >= fMaxEntriesToKeep) {
        historizables.removeLast();
      }
      historizables.addFirst(historizable);
    }
  }
478446
private void updateEntry(HashtableEntry entry)
                    throws IOException, EOFException, FileManagerException, ClassNotFoundException {
        //
        // We'll write the header, key, and data into a byte arry first,
        // then allocate, seek, and write with a single write operation.
        // It is necessary to buffer the data first like this because we cannot
        // determine the size of storage to allocate without first examining the
        // size of the serialize object.
        //

        //
        // Serialize key and data.  If the data is already a byte[] array, we can
        // bypass serialization.
        //
        byte[] serializedKey = entry.serializedKey;
        int keySize = 0;
        byte[] serializedValue = null;
        int valueSize = -1;
        int bytes = 0;
        byte[] serializedCacheValue = entry.serializedCacheValue;
        int cacheValueSize = -1;
        int dataSize = HTENTRY_OVERHEAD_SIZE;

        if (serializedKey == null) {
            if (keyout == null) {
                keyout = new ByteArrayPlusOutputStream(500);
            } else {
                keyout.reset();
            }
            serializeTimer.reset();
            ObjectOutputStream out = new ObjectOutputStream(keyout);
            out.writeObject(entry.key);
            out.close();
            serializedKey = keyout.getTheBuffer();
            keySize = keyout.size();
            bytes_serialized += keySize;
        } else {
            keySize = entry.serializedKey.length;
        }
        dataSize += keySize;

        if (entry.value != null) {
            if (isByteArray(entry.value)) {
                bytes = 1;
                serializedValue = (byte[]) entry.value;
                if (entry.valuelen != -1) {
                    valueSize = entry.valuelen;
                } else {
                    valueSize = serializedValue.length;
                }
            } else {
                if (dataout == null) {
                    dataout = new ByteArrayPlusOutputStream(500);
                } else {
                    dataout.reset();
                }
                ObjectOutputStream out = new ObjectOutputStream(dataout);
                out.writeObject(entry.value);
                out.close();
                serializedValue = dataout.getTheBuffer();
                valueSize = dataout.size();
                bytes_serialized += valueSize;
                //
                // If an unusally large object is written it bloats the buffer, which can
                // hog resources.  If this happens dump the static buffer and start a new 
                // one on the next write.
                //
                if (valueSize > 100000) {
                    dataout = null;
                }
            }
        }

        serialize_time += serializeTimer.elapsed();

        int allocateSize = DWORDSIZE + // room for "next"
                           SWORDSIZE + // room for fastpath hash key
                           DWORDSIZE + // room for old format: last-modified
                                       //          new format: validator expiration time(VET)
                           DWORDSIZE + // room for old format: last-referenced;   // LI4337-17
                                       //          new format: H-Word = unused 
                                       //                      L-word = cache value hashcode 
                           DWORDSIZE + // room for first_created
                           DWORDSIZE + // room for expiration (RET)
                           DWORDSIZE + // room for flag + object size
                           SWORDSIZE + // room for size of the key
                           keySize + // room for serialized key
                           SWORDSIZE + // room for bytes flag
                           SWORDSIZE; // room for size of the value

        if (valueSize != -1) {
            allocateSize += valueSize; // room for serialized value
            dataSize += valueSize; // add value size to data size 
        }

        if (this.bHasCacheValue && !entry.bAliasId) {
            allocateSize += SWORDSIZE; // room for size of cacheValue
            if (serializedCacheValue != null) { // any cacheValue?
                cacheValueSize = serializedCacheValue.length; // size of the cacheValue
                allocateSize += cacheValueSize; // room for serialized cacheValue
                dataSize += cacheValueSize; // add cacheValue size to data size
            }
        }
        if (dataSize % 512 != 0) { // size adjustment for 512 blocks
            dataSize = (dataSize / 512 + 1) * 512;
        }
        //System.out.println("**** HashtableOnDisk: id=" + entry.key + " size=" + dataSize + " allocateSize=" + allocateSize);
        long tempData = 0;
        if (entry.bAliasId) {
            tempData = HTENTRY_MAGIC + HTENTRY_VERSION + HTENTRY_ALIAS_ID + dataSize;
        } else {
            tempData = HTENTRY_MAGIC + HTENTRY_VERSION + dataSize;
        }

        // end write key and value
        //
        // physical allocation
        //

        // For testing for cache id 
        //String testId = (String)entry.key;
        //if (testId.indexOf("928") > 0 || testId.indexOf("1028") > 0) {
        //    throw new IOException(com.ibm.ws.cache.HTODDynacache.DISK_CACHE_IN_GB_OVER_LIMIT_MSG);
        //}
        // For testing for depid/template
        //if (!this.bHasCacheValue) {
        //    String testId = (String)entry.key;
        //    if (testId.indexOf("926") > 0) {
        //        throw new IOException(com.ibm.ws.cache.HTODDynacache.DISK_CACHE_IN_GB_OVER_LIMIT_MSG);
        //    }
        //}
        entry.location = filemgr.allocate(allocateSize);

        initWriteBuffer();
        headerout.writeLong(entry.next);
        headerout.writeInt(entry.hash);
        //headerout.writeLong(System.currentTimeMillis());  // old format: last update
        headerout.writeLong(entry.validatorExpiration); // new format: VET
        //headerout.writeLong(System.currentTimeMillis());  // old format: last reference
        headerout.writeInt(0); // new format: unused    // LI4337-17
        headerout.writeInt(entry.cacheValueHashcode); //             cache value hashcode
        headerout.writeLong(entry.first_created); // when object is first created
        headerout.writeLong(entry.expiration); // expiration (RET) 
        headerout.writeLong(tempData); // write magic, version, flag & data size 
        headerout.writeInt(keySize);
        headerout.flush();

        //
        // Physical write the record like this:
        filemgr.seek(entry.location);
        filemgr.write(headeroutbuf);
        //
        // int keysize;            length of key
        // byte[] serialized key;  The key
        // int valueSize           length of value
        // int value_is_byte_array 0 if value is serialized obj 1 if a byte array
        // byte[] value            serialized value
        //
        filemgr.write(serializedKey, 0, keySize);
        filemgr.writeInt(bytes);
        filemgr.writeInt(valueSize);
        if (valueSize != -1) {
            filemgr.write(serializedValue, 0, valueSize);
        }

        //
        // if there is any cacheValue
        // int cacheValueSize      size of cacheValue - -1 if cacheValue is empty
        // byte[] cacheValue   serialized cacheValue
        //
        if (this.bHasCacheValue) {
            filemgr.writeInt(cacheValueSize);
            if (cacheValueSize != -1) {
                filemgr.write(serializedCacheValue, 0, cacheValueSize);
            }
        }

        //if (serializedCacheValue != null) {
        //   traceDebug("updateEntry()", "cacheName=" + this.htoddc.cacheName + " key=" + entry.key + " allocateSize=" + allocateSize + " dataSize=" + dataSize + " valueSize=" + valueSize + " cacheValueSize=" + cacheValueSize);
        //} else {
        //    traceDebug("updateEntry()", "cacheName=" + this.htoddc.cacheName + " key=" + entry.key + " allocateSize=" + allocateSize + " valueSize=" + valueSize);
        //}
    }
626007
private void putEntry(String key, CacheHeader entry) {
        if (!mEntries.containsKey(key)) {
            mTotalSize += entry.size;
        } else {
            CacheHeader oldEntry = mEntries.get(key);
            mTotalSize += (entry.size - oldEntry.size);
        }
        mEntries.put(key, entry);
    }
167966
public static void addEntry(final File zip, final String path, final byte[] bytes) {
    operateInPlace(zip, new InPlaceAction() {
      public boolean act(File tmpFile) {
        addEntry(zip, path, bytes, tmpFile);
        return true;
      }
    });
  }
503089
public void addEntry(String key, String type, String widget, String params, String optional) {

        m_entries.add(new CmsWorkplaceUserInfoEntry(key, type, widget, params, optional));
    }
1261300
@Indexable(type = IndexableType.REINDEX)
	@Override
	public CommerceSubscriptionEntry addCommerceSubscriptionEntry(
		CommerceSubscriptionEntry commerceSubscriptionEntry) {
		commerceSubscriptionEntry.setNew(true);

		return commerceSubscriptionEntryPersistence.update(commerceSubscriptionEntry);
	}
439745
public void addFile(String zipEntry, byte[] data) throws IOException  {
		stream.putNextEntry(new ZipEntry(zipEntry));
		stream.write(data);
	}
1057775
public void add(BatchEntry batchEntry) throws DatabaseEngineException {
        bufferLock.lock();
        try {
            buffer.add(batchEntry);
            batch--;
        } finally {
            bufferLock.unlock();
        }
        if (batch <= 0) {
            flush();
        }
    }
825498
@Override
    void addEntry(int hash, K key, V value, int bucketIndex) {
	super.addEntry(hash, key, value, bucketIndex);

	// Remove eldest entry if instructed
	Entry<K, V> eldest = header.after;
	if (removeEldestEntry(eldest)) {
	    removeEntryForKey(eldest.key);
	}
    }
310964
public List.Entry addEntry(Token token,
                               Transaction transaction)
                    throws ObjectManagerException
    {
        final String methodName = "addEntry";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass, methodName, new Object[] { token,
                                                                transaction });

        // This differs from the default ObjectManager
        // behaviour because we optimistically add the link to the list and may need to 
        // undo this if the transaction backs out. Simply restoring before immages is not
        // enough because we dont lock the list during the prepare phase and other links
        // could be chanied off this one and commit their trandsactions before
        // this one.

        Link newLink = null;
        // Take a lock on transaction then the list itself, this protects the structure of the list 
        // and prevents deadlock with threads backing out the transaction. During backout the list 
        // lock is traven in the preBackout call back after the transaction lock has been taken. 
        synchronized (transaction.internalTransaction) {
            synchronized (this) {
                // Prevent other transactions using the list until its creation is commited.
                if (!(state == stateReady)
                    && !((state == stateAdded) && lockedBy(transaction))) {

                    if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                        trace.exit(this, cclass, methodName, new Object[] { new Integer(state),
                                                                           stateNames[state] });
                    throw new InvalidStateException(this, state, stateNames[state]);
                }

                // All optimistic replace updates to links in the list must be made
                // together, so we construct a single log record for all of them. 
                managedObjectsToAdd.clear();
                managedObjectsToReplace.clear();
                reservedSpaceInStore = storeSpaceForAdd();
                owningToken.objectStore.reserve((int) reservedSpaceInStore, false);

                // Create the new link and add it to its object store.
                newLink = new Link(this,
                                   token,
                                   tail,
                                   null,
                                   transaction);
                managedObjectsToAdd.add(newLink);

                // Chain the new Link in the list. If the transaction backs
                // out we will rewrite the links to remove the new one.
                if (head == null) // Only element in the list?
                {
                    head = newLink.getToken();
                    availableHead = head; // PK75215
                } else { // In the body of the list.
                    Link tailLink = (Link) tail.getManagedObject();
                    tailLink.next = newLink.getToken();
                    managedObjectsToReplace.add(tailLink);
                }
                tail = newLink.getToken();

                incrementSize(); // Adjust list length assuming we will commit.
                managedObjectsToReplace.add(this); // The anchor for the list.

                // Harden the updates. If the update fails, because the log is full,
                // we have affected the structure of the list so we will have to 
                // reverse the changes. Reserve enough space to reverse the update if the
                // transaction backs out.
                // TODO We need another optimistic replace with a more restricted state machine, this one
                // will allow an add after we have done prepare.
                try {
                    transaction.optimisticReplace(managedObjectsToAdd,
                                                  managedObjectsToReplace,
                                                  null, // No tokens to delete.
                                                  null, // No tokens to notify.
                                                  +logSpaceForDelete());
                    // Give up reserved space, but keep back enough to remove the entry if we have to.
                    owningToken.objectStore.reserve((int) (storeSpaceForRemove() - reservedSpaceInStore), false);

                } catch (InvalidStateException exception) {
                    // No FFDC Code Needed, user error.
                    // Remove the link we just added.
                    undoAdd(newLink);

                    if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                        trace.exit(this, cclass, methodName, exception);
                    throw exception;

                } catch (LogFileFullException exception) {
                    // No FFDC Code Needed, InternalTransaction has already done this.
                    // Remove the link we just added.
                    undoAdd(newLink);

                    if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                        trace.exit(this, cclass, methodName, exception);
                    throw exception;

                    // We should not see ObjectStoreFullException because we have preReserved 
                    // the ObjectStore space.
//        } catch (ObjectStoreFullException exception) {
//          // No FFDC Code Needed, InternalTransaction has already done this.
//          // Remove the link we just added.
//          undoAdd(newLink);
//          
//          if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
//            trace.exit(this, cclass, methodName, exception);
//          throw exception;
                } // try.

            } // synchronized (this).
        } // synchronized (transaction.internalTransaction)

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass, methodName, new Object[] { newLink });
        return (List.Entry) newLink;
    }
906068
private ITemplateSourceEntry addJarEntry(Map<String, ITemplateSourceEntry> entries, JarEntry jarEntry) {
		String name = jarEntry.getName().substring(basePathLength);
		if(name.isEmpty()) {
			name = "/";
		}

		ITemplateSourceEntry entry = new JarTemplateSourceEntry(name, jarEntry);
		entries.put(name, entry);
		return entry;
	}
1314711
public void addEntry(PartnerLogData logData) {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "addEntry", logData);

        _pltWriteLock.lock();

        try {
            addPartnerEntry(logData);
        } finally {
            _pltWriteLock.unlock();
        }

        if (tc.isEntryEnabled())
            Tr.exit(tc, "addEntry");
    }
599814
@Override
    public T add(Asset asset, ArchivePath target) throws IllegalArgumentException {
        this.getArchive().add(asset, target);
        return covarientReturn();
    }
1230897
private void addEntry(final Path pathToFile, final URL resource) throws IOException {

        final Path parent = pathToFile.getParent();
        if (parent != null) {
            addFolder(parent);
        }
        try (InputStream inputStream = resource.openStream()) {
            Files.copy(inputStream, pathToFile);
        }
    }
835281
protected void addEntry (E entry)
    {
        if (_entryFilter == null || _entryFilter.apply(entry)) {
            int index = _keys.insertSorted(getKey(entry));
            _table.insertDatum(entry, index);
        }
    }