Example usage for java.util BitSet set

List of usage examples for java.util BitSet set

Introduction

In this page you can find the example usage for java.util BitSet set.

Prototype

public void set(int fromIndex, int toIndex) 

Source Link

Document

Sets the bits from the specified fromIndex (inclusive) to the specified toIndex (exclusive) to true .

Usage

From source file:com.moadbus.banking.iso.core.protocol.MessageFactory.java

/**
 * Creates a new message instance from the buffer, which must contain a
 * valid ISO8583 message. If the factory is set to use binary messages then
 * it will try to parse a binary message.
 *
 * @param buf// w ww.j  a v a  2s.  c  o  m
 *            The byte buffer containing the message. Must not include the
 *            length header.
 * @param isoHeaderLength
 *            The expected length of the ISO header, after which the message
 *            type and the rest of the message must come.
 */
public IsoMessage parseMessage(byte[] buf, int isoHeaderLength) throws ParseException {
    log.debug(" Message length =" + buf.length);
    IsoMessage m = new IsoMessage(isoHeaderLength > 0 ? new String(buf, 0, isoHeaderLength) : null);
    // TODO it only parses ASCII messages for now
    int type = 0;
    if (useBinary) {
        type = ((buf[isoHeaderLength] & 0xff) << 8) | (buf[isoHeaderLength + 1] & 0xff);
    } else {
        type = ((buf[isoHeaderLength] - 48) << 12) | ((buf[isoHeaderLength + 1] - 48) << 8)
                | ((buf[isoHeaderLength + 2] - 48) << 4) | (buf[isoHeaderLength + 3] - 48);
    }
    m.setType(type);
    // Parse the bitmap (primary first)
    BitSet bs = new BitSet(64);
    int pos = 0;
    if (useBinary) {
        for (int i = isoHeaderLength + 2; i < isoHeaderLength + 10; i++) {
            int bit = 128;
            for (int b = 0; b < 8; b++) {
                bs.set(pos++, (buf[i] & bit) != 0);
                bit >>= 1;
            }
        }
        // Check for secondary bitmap and parse if necessary
        if (bs.get(0)) {
            for (int i = isoHeaderLength + 10; i < isoHeaderLength + 18; i++) {
                int bit = 128;
                for (int b = 0; b < 8; b++) {
                    bs.set(pos++, (buf[i] & bit) != 0);
                    bit >>= 1;
                }
            }
            pos = 18 + isoHeaderLength;
        } else {
            pos = 10 + isoHeaderLength;
        }
    } else {
        for (int i = isoHeaderLength + 4; i < isoHeaderLength + 20; i++) {
            int hex = Integer.parseInt(new String(buf, i, 1), 16);
            bs.set(pos++, (hex & 8) > 0);
            bs.set(pos++, (hex & 4) > 0);
            bs.set(pos++, (hex & 2) > 0);
            bs.set(pos++, (hex & 1) > 0);
        }
        // Check for secondary bitmap and parse it if necessary
        if (bs.get(0)) {
            for (int i = isoHeaderLength + 20; i < isoHeaderLength + 36; i++) {
                int hex = Integer.parseInt(new String(buf, i, 1), 16);
                bs.set(pos++, (hex & 8) > 0);
                bs.set(pos++, (hex & 4) > 0);
                bs.set(pos++, (hex & 2) > 0);
                bs.set(pos++, (hex & 1) > 0);
            }
            pos = 36 + isoHeaderLength;
        } else {
            pos = 20 + isoHeaderLength;
        }
    }
    // Parse each field
    Map<Integer, FieldParseInfo> parseGuide = parseMap.get(type);
    List<Integer> index = parseOrder.get(type);
    log.debug(" Parsing bit ");
    log.debug(" Total index =" + index.size());
    for (Integer i : index) {
        FieldParseInfo fpi = parseGuide.get(i);
        if (i == 124) {
            if (1 == 1)
                ;
        }
        log.debug((i) + ",");
        if (bs.get(i - 1)) {
            IsoValue val = useBinary ? fpi.parseBinary(buf, pos) : fpi.parse(buf, pos);
            log.debug("bit [" + i + "] len=" + val.getLength() + " val=" + val);
            m.setField(i, val);
            if (useBinary && !(val.getType() == IsoType.ALPHA || val.getType() == IsoType.LLVAR
                    || val.getType() == IsoType.LLLVAR)) {
                pos += (val.getLength() / 2) + (val.getLength() % 2);
            } else {
                pos += val.getLength();
            }
            if (val.getType() == IsoType.LLVAR) {
                pos += useBinary ? 1 : 2;
            } else if (val.getType() == IsoType.LLLVAR) {
                pos += useBinary ? 2 : 3;
            }
        }
    }
    log.debug("...done");
    return m;
}

From source file:com.oltpbenchmark.benchmarks.seats.SEATSWorker.java

private boolean executeDeleteReservation(DeleteReservation proc) throws SQLException {
    // Pull off the first cached reservation and drop it on the cluster...
    final Reservation r = CACHE_RESERVATIONS.get(CacheType.PENDING_DELETES).poll();
    if (r == null) {
        return (false);
    }/*from   w  w  w  .  j a  v  a2 s.  c  o  m*/
    int rand = rng.number(1, 100);

    // Parameters
    long f_id = r.flight_id.encode();
    Long c_id = null;
    String c_id_str = null;
    String ff_c_id_str = null;
    Long ff_al_id = null;

    // Delete with the Customer's id as a string 
    if (rand <= SEATSConstants.PROB_DELETE_WITH_CUSTOMER_ID_STR) {
        c_id_str = Long.toString(r.customer_id.encode());
    }
    // Delete using their FrequentFlyer information
    else if (rand <= SEATSConstants.PROB_DELETE_WITH_CUSTOMER_ID_STR
            + SEATSConstants.PROB_DELETE_WITH_FREQUENTFLYER_ID_STR) {
        ff_c_id_str = Long.toString(r.customer_id.encode());
        ff_al_id = r.flight_id.getAirlineId();
    }
    // Delete using their Customer id
    else {
        c_id = r.customer_id.encode();
    }

    if (LOG.isTraceEnabled())
        LOG.trace("Calling " + proc);
    proc.run(conn, f_id, c_id, c_id_str, ff_c_id_str, ff_al_id);
    conn.commit();

    // We can remove this from our set of full flights because know that there is now a free seat
    BitSet seats = getSeatsBitSet(r.flight_id);
    seats.set(r.seatnum, false);

    // And then put it up for a pending insert
    if (rng.nextInt(100) < SEATSConstants.PROB_REQUEUE_DELETED_RESERVATION) {
        CACHE_RESERVATIONS.get(CacheType.PENDING_INSERTS).add(r);
    }

    return (true);
}

From source file:MSUmpire.SpectrumParser.mzXMLParser.java

@Override
public ScanCollection GetScanDIAMS2(XYData DIAWindow, boolean IncludePeak, float startTime, float endTime) {
    if (dIA_Setting == null) {
        Logger.getRootLogger().error(filename + " is not DIA data");
        return null;
    }//from  w  w w  . j a v  a 2  s  .co  m
    ScanCollection swathScanCollection = new ScanCollection(parameter.Resolution);
    List<MzXMLthreadUnit> ScanList = new ArrayList<>();

    int StartScanNo = 0;
    int EndScanNo = 0;

    StartScanNo = GetStartScan(startTime);
    EndScanNo = GetEndScan(endTime);
    //        ArrayList<Integer> IncludedScans=new ArrayList<>();
    final BitSet IncludedScans = new BitSet();
    for (int scannum : dIA_Setting.DIAWindows.get(DIAWindow)) {
        if (scannum >= StartScanNo && scannum <= EndScanNo) {
            IncludedScans.set(scannum, true);
        }
    }
    ScanList = ParseScans(IncludedScans);
    for (MzXMLthreadUnit result : ScanList) {
        swathScanCollection.AddScan(result.scan);
        swathScanCollection.ElutionTimeToScanNoMap.put(result.scan.RetentionTime, result.scan.ScanNum);
    }
    ScanList.clear();
    ScanList = null;
    return swathScanCollection;
}

From source file:MSUmpire.SpectrumParser.mzXMLParser.java

@Override
public ScanCollection GetScanCollectionMS1Window(XYData MS1Window, boolean IncludePeak, float startTime,
        float endTime) {
    if (dIA_Setting == null) {
        Logger.getRootLogger().error(filename + " is not DIA data");
        return null;
    }/*from  w w w  .  jav  a  2 s .c om*/
    ScanCollection MS1WindowScanCollection = new ScanCollection(parameter.Resolution);

    List<MzXMLthreadUnit> ScanList = null;

    int StartScanNo = 0;
    int EndScanNo = 0;

    StartScanNo = GetStartScan(startTime);
    EndScanNo = GetEndScan(endTime);
    //        ArrayList<Integer> IncludedScans=new ArrayList<>();
    final BitSet IncludedScans = new BitSet();
    for (int scannum : dIA_Setting.MS1Windows.get(MS1Window)) {
        if (scannum >= StartScanNo && scannum <= EndScanNo) {
            IncludedScans.set(scannum, true);
        }
    }

    ScanList = ParseScans(IncludedScans);

    for (MzXMLthreadUnit result : ScanList) {
        MS1WindowScanCollection.AddScan(result.scan);
        MS1WindowScanCollection.ElutionTimeToScanNoMap.put(result.scan.RetentionTime, result.scan.ScanNum);
    }
    ScanList.clear();
    ScanList = null;

    return MS1WindowScanCollection;
}

From source file:org.apache.hadoop.hive.serde2.compression.SnappyCompDe.java

/**
 * Compress a set of columns.//from  w ww .  j av a2s . com
 *
 * The header contains a compressed array of data types.
 * The body contains compressed columns and their metadata.
 * The footer contains a compressed array of chunk sizes. The final four bytes of the footer encode the byte size of that compressed array.
 *
 * @param colSet
 *
 * @return ByteBuffer representing the compressed set.
 */
@Override
public ByteBuffer compress(ColumnBuffer[] colSet) {

    // Many compression libraries allow you to avoid allocation of intermediate arrays.
    // To use these API, we need to preallocate the output container.

    // Reserve space for the header.
    int[] dataType = new int[colSet.length];
    int maxCompressedSize = Snappy.maxCompressedLength(4 * dataType.length);

    // Reserve space for the compressed nulls BitSet for each column.
    maxCompressedSize += colSet.length * Snappy.maxCompressedLength((colSet.length / 8) + 1);

    // Track the length of `List<Integer> compressedSize` which will be declared later.
    int uncompressedFooterLength = 1 + 2 * colSet.length;

    for (int colNum = 0; colNum < colSet.length; ++colNum) {
        // Reserve space for the compressed columns.
        dataType[colNum] = colSet[colNum].getType().toTType().getValue();
        switch (TTypeId.findByValue(dataType[colNum])) {
        case BOOLEAN_TYPE:
            maxCompressedSize += Integer.SIZE / Byte.SIZE; // This is for the encoded length.
            maxCompressedSize += Snappy.maxCompressedLength((colSet.length / 8) + 1);
            break;
        case TINYINT_TYPE:
            maxCompressedSize += Snappy.maxCompressedLength(colSet.length);
            break;
        case SMALLINT_TYPE:
            maxCompressedSize += Snappy.maxCompressedLength(colSet.length * Short.SIZE / Byte.SIZE);
            break;
        case INT_TYPE:
            maxCompressedSize += Snappy.maxCompressedLength(colSet.length * Integer.SIZE / Byte.SIZE);
            break;
        case BIGINT_TYPE:
            maxCompressedSize += Snappy.maxCompressedLength(colSet.length * Long.SIZE / Byte.SIZE);
            break;
        case DOUBLE_TYPE:
            maxCompressedSize += Snappy.maxCompressedLength(colSet.length * Double.SIZE / Byte.SIZE);
            break;
        case BINARY_TYPE:
            // Reserve space for the size of the compressed array of row sizes.
            maxCompressedSize += Snappy.maxCompressedLength(colSet.length * Integer.SIZE / Byte.SIZE);

            // Reserve space for the size of the compressed flattened bytes.
            for (ByteBuffer nextBuffer : colSet[colNum].toTColumn().getBinaryVal().getValues()) {
                maxCompressedSize += Snappy.maxCompressedLength(nextBuffer.limit());
            }

            // Add an additional value to the list of compressed chunk sizes (length of `rowSize` array).
            uncompressedFooterLength++;

            break;
        case STRING_TYPE:
            // Reserve space for the size of the compressed array of row sizes.
            maxCompressedSize += Snappy.maxCompressedLength(colSet.length * Integer.SIZE / Byte.SIZE);

            // Reserve space for the size of the compressed flattened bytes.
            for (String nextString : colSet[colNum].toTColumn().getStringVal().getValues()) {
                maxCompressedSize += Snappy
                        .maxCompressedLength(nextString.getBytes(StandardCharsets.UTF_8).length);
            }

            // Add an additional value to the list of compressed chunk sizes (length of `rowSize` array).
            uncompressedFooterLength++;

            break;
        default:
            throw new IllegalStateException("Unrecognized column type");
        }
    }
    // Reserve space for the footer.
    maxCompressedSize += Snappy.maxCompressedLength(uncompressedFooterLength * Integer.SIZE / Byte.SIZE);

    // Allocate the output container.
    ByteBuffer output = ByteBuffer.allocate(maxCompressedSize);

    // Allocate the footer. This goes in the footer because we don't know the chunk sizes until after
    // the columns have been compressed and written.
    ArrayList<Integer> compressedSize = new ArrayList<Integer>(uncompressedFooterLength);

    // Write to the output buffer.
    try {
        // Write the header.
        compressedSize.add(writePrimitives(dataType, output));

        // Write the compressed columns and metadata.
        for (int colNum = 0; colNum < colSet.length; colNum++) {
            switch (TTypeId.findByValue(dataType[colNum])) {
            case BOOLEAN_TYPE: {
                TBoolColumn column = colSet[colNum].toTColumn().getBoolVal();

                List<Boolean> bools = column.getValues();
                BitSet bsBools = new BitSet(bools.size());
                for (int rowNum = 0; rowNum < bools.size(); rowNum++) {
                    bsBools.set(rowNum, bools.get(rowNum));
                }

                compressedSize.add(writePrimitives(column.getNulls(), output));

                // BitSet won't write trailing zeroes so we encode the length
                output.putInt(column.getValuesSize());

                compressedSize.add(writePrimitives(bsBools.toByteArray(), output));

                break;
            }
            case TINYINT_TYPE: {
                TByteColumn column = colSet[colNum].toTColumn().getByteVal();
                compressedSize.add(writePrimitives(column.getNulls(), output));
                compressedSize.add(writeBoxedBytes(column.getValues(), output));
                break;
            }
            case SMALLINT_TYPE: {
                TI16Column column = colSet[colNum].toTColumn().getI16Val();
                compressedSize.add(writePrimitives(column.getNulls(), output));
                compressedSize.add(writeBoxedShorts(column.getValues(), output));
                break;
            }
            case INT_TYPE: {
                TI32Column column = colSet[colNum].toTColumn().getI32Val();
                compressedSize.add(writePrimitives(column.getNulls(), output));
                compressedSize.add(writeBoxedIntegers(column.getValues(), output));
                break;
            }
            case BIGINT_TYPE: {
                TI64Column column = colSet[colNum].toTColumn().getI64Val();
                compressedSize.add(writePrimitives(column.getNulls(), output));
                compressedSize.add(writeBoxedLongs(column.getValues(), output));
                break;
            }
            case DOUBLE_TYPE: {
                TDoubleColumn column = colSet[colNum].toTColumn().getDoubleVal();
                compressedSize.add(writePrimitives(column.getNulls(), output));
                compressedSize.add(writeBoxedDoubles(column.getValues(), output));
                break;
            }
            case BINARY_TYPE: {
                TBinaryColumn column = colSet[colNum].toTColumn().getBinaryVal();

                // Initialize the array of row sizes.
                int[] rowSizes = new int[column.getValuesSize()];
                int totalSize = 0;
                for (int rowNum = 0; rowNum < column.getValuesSize(); rowNum++) {
                    rowSizes[rowNum] = column.getValues().get(rowNum).limit();
                    totalSize += column.getValues().get(rowNum).limit();
                }

                // Flatten the data for Snappy for a better compression ratio.
                ByteBuffer flattenedData = ByteBuffer.allocate(totalSize);
                for (int rowNum = 0; rowNum < column.getValuesSize(); rowNum++) {
                    flattenedData.put(column.getValues().get(rowNum));
                }

                // Write nulls bitmap.
                compressedSize.add(writePrimitives(column.getNulls(), output));

                // Write the list of row sizes.
                compressedSize.add(writePrimitives(rowSizes, output));

                // Write the compressed, flattened data.
                compressedSize.add(writePrimitives(flattenedData.array(), output));

                break;
            }
            case STRING_TYPE: {
                TStringColumn column = colSet[colNum].toTColumn().getStringVal();

                // Initialize the array of row sizes.
                int[] rowSizes = new int[column.getValuesSize()];
                int totalSize = 0;
                for (int rowNum = 0; rowNum < column.getValuesSize(); rowNum++) {
                    rowSizes[rowNum] = column.getValues().get(rowNum).length();
                    totalSize += column.getValues().get(rowNum).length();
                }

                // Flatten the data for Snappy for a better compression ratio.
                StringBuilder flattenedData = new StringBuilder(totalSize);
                for (int rowNum = 0; rowNum < column.getValuesSize(); rowNum++) {
                    flattenedData.append(column.getValues().get(rowNum));
                }

                // Write nulls bitmap.
                compressedSize.add(writePrimitives(column.getNulls(), output));

                // Write the list of row sizes.
                compressedSize.add(writePrimitives(rowSizes, output));

                // Write the flattened data.
                compressedSize.add(
                        writePrimitives(flattenedData.toString().getBytes(StandardCharsets.UTF_8), output));

                break;
            }
            default:
                throw new IllegalStateException("Unrecognized column type");
            }
        }

        // Write the footer.
        output.putInt(writeBoxedIntegers(compressedSize, output));

    } catch (IOException e) {
        e.printStackTrace();
    }
    output.flip();
    return output;
}

From source file:jetbrains.buildServer.clouds.azure.asm.connector.AzureApiConnector.java

private int getPortNumber(final String serviceName,
        final HostedServiceGetDetailedResponse.Deployment deployment) {
    final BitSet busyPorts = new BitSet();
    busyPorts.set(MIN_PORT_NUMBER, MAX_PORT_NUMBER);

    for (RoleInstance instance : deployment.getRoleInstances()) {
        for (InstanceEndpoint endpoint : instance.getInstanceEndpoints()) {
            final int port = endpoint.getPort();
            if (port >= MIN_PORT_NUMBER && port <= MAX_PORT_NUMBER) {
                busyPorts.set(port, false);
            }//from w  w  w .j a  va 2 s.com
        }
    }

    for (Role role : deployment.getRoles()) {
        for (ConfigurationSet conf : role.getConfigurationSets()) {
            for (InputEndpoint endpoint : conf.getInputEndpoints()) {
                final int port = endpoint.getPort();
                if (port >= MIN_PORT_NUMBER && port <= MAX_PORT_NUMBER) {
                    busyPorts.set(port, false);
                }
            }
        }
    }

    final Map<String, Integer> map = DEPLOYMENT_OPS.get(serviceName);
    if (map != null) {
        final Iterator<String> iter = map.keySet().iterator();
        while (iter.hasNext()) {
            final String operationId = iter.next();
            if (isActionFinished(operationId)) {
                iter.remove();
            } else {
                busyPorts.set(map.get(operationId), false);
            }
        }
    }

    int portNumber = MIN_PORT_NUMBER;
    for (int i = MIN_PORT_NUMBER; i <= MAX_PORT_NUMBER; i++) {
        if (busyPorts.get(i)) {
            portNumber = i;
            break;
        }
    }

    return portNumber;
}

From source file:hivemall.ftvec.ranking.ItemPairsSamplingUDTF.java

private void sampleWithoutReplacement(int numPosItems, int numNegItems, @Nonnull final BitSet bitset)
        throws HiveException {
    final BitSet bitsetForPosSampling = bitset;
    final BitSet bitsetForNegSampling = BitSet.valueOf(bitset.toLongArray());

    final int numSamples = Math.max(1, Math.round(numPosItems * samplingRate));
    for (int s = 0; s < numSamples; s++) {
        int nth = _rand.nextInt(numPosItems);
        int i = BitUtils.indexOfSetBit(bitsetForPosSampling, nth);
        if (i == -1) {
            throw new UDFArgumentException("Cannot find a value for " + nth + "-th element in bitset "
                    + bitset.toString() + " where numPosItems = " + numPosItems);
        }/*from   w  ww . ja v  a2s . com*/
        bitsetForPosSampling.set(i, false);
        --numPosItems;

        nth = _rand.nextInt(numNegItems);
        int j = BitUtils.indexOfClearBit(bitsetForNegSampling, nth, maxItemId);
        if (j < 0 || j > maxItemId) {
            throw new UDFArgumentException("j MUST be in [0," + maxItemId + "] but j was " + j);
        }
        bitsetForNegSampling.set(j, true);
        --numNegItems;

        posItemId.set(i);
        negItemId.set(j);
        forward(forwardObjs);

        if (numPosItems <= 0) {
            // cannot draw a positive example anymore
            return;
        } else if (numNegItems <= 0) {
            // cannot draw a negative example anymore
            return;
        }
    }
}

From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java

private void writeFileEmptyStreams(final DataOutput header) throws IOException {
    boolean hasEmptyStreams = false;
    for (final SevenZArchiveEntry entry : files) {
        if (!entry.hasStream()) {
            hasEmptyStreams = true;//from w  ww  .ja  v  a2 s  .c o m
            break;
        }
    }
    if (hasEmptyStreams) {
        header.write(NID.kEmptyStream);
        final BitSet emptyStreams = new BitSet(files.size());
        for (int i = 0; i < files.size(); i++) {
            emptyStreams.set(i, !files.get(i).hasStream());
        }
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final DataOutputStream out = new DataOutputStream(baos);
        writeBits(out, emptyStreams, files.size());
        out.flush();
        final byte[] contents = baos.toByteArray();
        writeUint64(header, contents.length);
        header.write(contents);
    }
}

From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java

private void writeFileATimes(final DataOutput header) throws IOException {
    int numAccessDates = 0;
    for (final SevenZArchiveEntry entry : files) {
        if (entry.getHasAccessDate()) {
            ++numAccessDates;//from w w  w.ja  v  a  2  s  .  co m
        }
    }
    if (numAccessDates > 0) {
        header.write(NID.kATime);

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final DataOutputStream out = new DataOutputStream(baos);
        if (numAccessDates != files.size()) {
            out.write(0);
            final BitSet aTimes = new BitSet(files.size());
            for (int i = 0; i < files.size(); i++) {
                aTimes.set(i, files.get(i).getHasAccessDate());
            }
            writeBits(out, aTimes, files.size());
        } else {
            out.write(1); // "allAreDefined" == true
        }
        out.write(0);
        for (final SevenZArchiveEntry entry : files) {
            if (entry.getHasAccessDate()) {
                out.writeLong(Long.reverseBytes(SevenZArchiveEntry.javaTimeToNtfsTime(entry.getAccessDate())));
            }
        }
        out.flush();
        final byte[] contents = baos.toByteArray();
        writeUint64(header, contents.length);
        header.write(contents);
    }
}

From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java

private void writeFileCTimes(final DataOutput header) throws IOException {
    int numCreationDates = 0;
    for (final SevenZArchiveEntry entry : files) {
        if (entry.getHasCreationDate()) {
            ++numCreationDates;//  w  w  w.j a  v  a2  s  .  c om
        }
    }
    if (numCreationDates > 0) {
        header.write(NID.kCTime);

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final DataOutputStream out = new DataOutputStream(baos);
        if (numCreationDates != files.size()) {
            out.write(0);
            final BitSet cTimes = new BitSet(files.size());
            for (int i = 0; i < files.size(); i++) {
                cTimes.set(i, files.get(i).getHasCreationDate());
            }
            writeBits(out, cTimes, files.size());
        } else {
            out.write(1); // "allAreDefined" == true
        }
        out.write(0);
        for (final SevenZArchiveEntry entry : files) {
            if (entry.getHasCreationDate()) {
                out.writeLong(
                        Long.reverseBytes(SevenZArchiveEntry.javaTimeToNtfsTime(entry.getCreationDate())));
            }
        }
        out.flush();
        final byte[] contents = baos.toByteArray();
        writeUint64(header, contents.length);
        header.write(contents);
    }
}