/* (non-Javadoc)
@see tuwien.auto.calimero.mgmt.ManagementClient#writeDomainAddress(byte[])
8360
public void writeDomainAddress(byte[] domain) throws KNXTimeoutException,
		KNXLinkClosedException
	{
		if (domain.length != 2 && domain.length != 6)
			throw new KNXIllegalArgumentException("invalid length of domain address");
		tl.broadcast(true, priority, DataUnitBuilder.createAPDU(DOA_WRITE, domain));
	}
182679
public void write(GroupAddress dst, String value) throws KNXTimeoutException,
		KNXFormatException, KNXLinkClosedException
	{
		final DPTXlatorString t = new DPTXlatorString(DPTXlatorString.DPT_STRING_8859_1);
		t.setValue(value);
		write(dst, priority, t);
	}
937603
@Override
  public void write(JsonWriterImpl out, byte []value)
  {
    StringBuilder sb = new StringBuilder();

    Base64Util.encode(sb, value, 0, value.length);

    out.write(sb.toString());
  }
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"
                            );
    }
739317
@Override
    protected int writeBytesWireFormat ( byte[] dst, int dstIndex ) {
        int start = dstIndex;
        SMBUtil.writeInt2(9, dst, dstIndex);
        SMBUtil.writeInt2(this.treeFlags, dst, dstIndex + 2);
        dstIndex += 4;

        byte[] data = this.path.getBytes(StandardCharsets.UTF_16LE);
        int offsetOffset = dstIndex;
        SMBUtil.writeInt2(data.length, dst, dstIndex + 2);
        dstIndex += 4;
        SMBUtil.writeInt2(dstIndex - getHeaderStart(), dst, offsetOffset);

        System.arraycopy(data, 0, dst, dstIndex, data.length);
        dstIndex += data.length;
        return dstIndex - start;
    }
395464
void writeBytes(byte[] bytes) throws IOException {
        int size = bytes.length;
        if (size < 256) {
            output.writeByte(BIN_8);
            output.writeByte(size);
        } else if (size < 65536) {
            output.writeByte(BIN_16);
            output.writeShort(size);
        } else {
            output.writeByte(BIN_32);
            output.writeInt(size);
        }
        output.write(bytes);
    }
986147
@Override
  public void write(DataOutput out) throws IOException {
    Text.writeString(out, getJobId());
    out.writeDouble(getCpuUsageGHz());
    out.writeDouble(getMemUsageGB());
  }
1134599
@Override
    protected int writeBytesWireFormat ( byte[] dst, int dstIndex ) {
        int start = dstIndex;
        SMBUtil.writeInt2(4, dst, dstIndex);
        dstIndex += 4;
        return dstIndex - start;
    }
907054
@Override
    protected int writeBytesWireFormat ( byte[] dst, int dstIndex ) {
        int start = dstIndex;
        SMBUtil.writeInt2(48, dst, dstIndex);
        SMBUtil.writeInt2(this.locks.length, dst, dstIndex + 2);
        dstIndex += 4;
        SMBUtil.writeInt4( ( ( this.lockSequenceNumber & 0xF ) << 28 ) | ( this.lockSequenceIndex & 0x0FFFFFFF ), dst, dstIndex);
        dstIndex += 4;
        System.arraycopy(this.fileId, 0, dst, dstIndex, 16);
        dstIndex += 16;

        for ( Smb2Lock l : this.locks ) {
            dstIndex += l.encode(dst, dstIndex);
        }
        return dstIndex - start;
    }
745823
@Override
    public boolean isAnyLocalAddress() {
        byte test = 0x00;
        for (int i = 0; i < INADDRSZ; i++) {
            test |= ipaddress[i];
        }
        return (test == 0x00);
    }
371907
public void writeToNoAddrs(Address src, DataOutput out, short ... excluded_headers) throws IOException {
        byte leading=0;

        boolean write_src_addr=src == null || sender != null && !sender.equals(src);

        if(write_src_addr)
            leading=Util.setFlag(leading, SRC_SET);

        if(buf != null)
            leading=Util.setFlag(leading, BUF_SET);

        // 1. write the leading byte first
        out.write(leading);

        // 2. the flags (e.g. OOB, LOW_PRIO)
        out.writeShort(flags);

        // 4. src_addr
        if(write_src_addr)
            Util.writeAddress(sender, out);

        // 5. headers
        Header[] hdrs=this.headers;
        int size=Headers.size(hdrs, excluded_headers);
        out.writeShort(size);
        if(size > 0) {
            for(Header hdr : hdrs) {
                if(hdr == null)
                    break;
                short id=hdr.getProtId();
                if(Util.containsId(id, excluded_headers))
                    continue;
                out.writeShort(id);
                writeHeader(hdr, out);
            }
        }

        // 6. buf
        if(buf != null) {
            out.writeInt(length);
            out.write(buf, offset, length);
        }
    }
1214330
public byte[] sendBindResp(OutputStream os, int commandId,
            int sequenceNumber, String systemId, InterfaceVersion interfaceVersion) throws PDUStringException,
            IOException {
        synchronized (os) {
            return pduSender.sendBindResp(os, commandId, sequenceNumber,
                    systemId, interfaceVersion);
        }
    }
1018060
public void sendDTMF(String connId, String digits) throws WorkspaceApiException {
        this.sendDTMF(connId, digits, null, null);
    }
1058007
private int writeBuffer(java.nio.ByteBuffer byteBuffer,
                            long byteAddress)
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        "writeBuffer",
                        new Object[] { new Integer(byteBuffer.hashCode()), new Long(byteAddress) }
                            );

        // Write the bytes.
        int bytesWritten = 0;
        try {
            while (byteBuffer.hasRemaining()) {
                bytesWritten = bytesWritten + storeChannel.write(byteBuffer,
                                                                 byteAddress + bytesWritten);
            } // while (byteBuffer.hasRemaining()).
        } catch (java.io.IOException exception) {
            // No FFDC Code Needed.
            ObjectManager.ffdc.processException(this, cclass, "writeBuffer", exception, "1:833:1.39");

            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this,
                           cclass,
                           "writeBuffer");

            // cannot continue
            objectManagerState.requestShutdown();
            throw new PermanentIOException(this,
                                           exception);
        } // catch.

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       "writeBuffer",
                       new Object[] { new Integer(bytesWritten) });
        return bytesWritten;
    }
507578
void writeODataMetadata(String contextURL) throws XMLStreamException {

        xmlWriter.writeNamespace(METADATA, nsConfigurationProvider.getOdataMetadataNs());
        xmlWriter.writeNamespace(ODATA_DATA, nsConfigurationProvider.getOdataDataNs());
        xmlWriter.writeDefaultNamespace(ATOM_NS);
        xmlWriter.writeAttribute(nsConfigurationProvider.getOdataMetadataNs(), ODATA_CONTEXT, contextURL);
        xmlWriter.writeAttribute(ODATA_XML_BASE, oDataUri.serviceRoot());
    }
792998
protected void sendLocalAddress(Address local_addr) throws Exception {
        try {
            // write the cookie
            out.write(cookie, 0, cookie.length);

            // write the version
            out.writeShort(Version.version);
            out.writeShort(local_addr.serializedSize()); // address size
            local_addr.writeTo(out);
            out.flush(); // needed ?
            updateLastAccessed();
        }
        catch(Exception ex) {
            server.socket_factory.close(this.sock);
            connected=false;
            throw ex;
        }
    }
1012610
void doMain(String[] args, boolean throwOnError) throws Exception {
		if (args.length == 0) {
			usage(throwOnError, "no arguments specified");
			return;
		} else if (args.length > 2) {
			usage(throwOnError, "improper number of arguments:" + Arrays.toString(args));
			return;
		}

		// check for --usage or --help
		if (args.length == 1 && ("--usage".equals(args[0]) || "--help".equals(args[0]))) {
			usage(throwOnError, null);
			return;
		}

		CommandLineJmxClient jmxClient;
		if (args[0].indexOf('/') >= 0) {
			jmxClient = new CommandLineJmxClient(args[0]);
		} else {
			String[] parts = args[0].split(":");
			if (parts.length != 2) {
				usage(throwOnError, "argument should be in 'hostname:port' format, not: " + args[0]);
				return;
			}
			String hostName = parts[0];
			int port = 0;
			try {
				port = Integer.parseInt(parts[1]);
			} catch (NumberFormatException e) {
				usage(throwOnError, "port number not in the right format: " + parts[1]);
				return;
			}
			jmxClient = new CommandLineJmxClient(hostName, port);
		}

		if (args.length == 1) {
			jmxClient.runCommandLine();
		} else if (args.length == 2) {
			jmxClient.runBatchFile(new File(args[1]));
		}
	}