Example usage for java.io DataOutputStream writeUTF

List of usage examples for java.io DataOutputStream writeUTF

Introduction

In this page you can find the example usage for java.io DataOutputStream writeUTF.

Prototype

public final void writeUTF(String str) throws IOException 

Source Link

Document

Writes a string to the underlying output stream using modified UTF-8 encoding in a machine-independent manner.

Usage

From source file:com.trigger_context.Main_Service.java

private void sendFile(DataOutputStream out, String Path) {
    Log.i(Main_Service.LOG_TAG, "SendFile--Start");
    File infile = new File(Path);
    String FileName = null;/* w w w .j a va2s .  c o m*/
    try {

        FileName = Path.substring(Path.lastIndexOf("/") + 1);
        out.writeUTF(FileName);
        out.writeLong(infile.length());
    } catch (IOException e) {
        Log.i(Main_Service.LOG_TAG, "SendFile--error sending filename length");
    }

    byte[] mybytearray = new byte[(int) infile.length()];

    FileInputStream fis = null;
    ;
    try {
        fis = new FileInputStream(infile);
    } catch (FileNotFoundException e1) {
        Log.i(Main_Service.LOG_TAG, "sendFile--Error file not found");
    }
    BufferedInputStream bis = new BufferedInputStream(fis);

    DataInputStream dis = new DataInputStream(bis);
    try {
        dis.readFully(mybytearray, 0, mybytearray.length);
    } catch (IOException e1) {
        Log.i(Main_Service.LOG_TAG, "sendFile--Error while reading bytes from file");

    }

    try {
        out.write(mybytearray, 0, mybytearray.length);
    } catch (IOException e1) {
        Log.i(Main_Service.LOG_TAG, "sendFile--error while sending");
    }

    try {
        dis.close();
        bis.close();
        fis.close();
    } catch (IOException e) {

        Log.i(Main_Service.LOG_TAG, "sendFile--error in closing streams");
    }

}

From source file:com.momock.http.HttpSession.java

void writeHeaders() {
    try {/* w w w  .  ja  va 2s .co  m*/
        DataOutputStream dout = new DataOutputStream(new FileOutputStream(fileInfo));
        int headerCount = headers.size();
        dout.writeInt(headerCount);
        for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
            String key = entry.getKey();
            List<String> values = entry.getValue();
            dout.writeUTF(key);
            dout.writeInt(values.size());
            for (String value : values) {
                dout.writeUTF(value);
            }
        }
        dout.close();
    } catch (IOException e) {
        Logger.error(e);
    }
}

From source file:org.openxdata.server.service.impl.FormDownloadServiceImpl.java

@Override
public void downloadMenuText(InputStream is, OutputStream os, String serializerName, String locale) {
    DataOutputStream dos = new DataOutputStream(os);

    try {//  w w  w. jav  a  2 s . c o m
        List<MobileMenuText> text = utilityService.getMobileMenuText(locale);
        if (text == null || text.size() == 0)
            dos.writeShort(0);
        else {
            dos.writeShort(text.size());
            for (MobileMenuText txt : text) {
                dos.writeShort(txt.getMenuId());
                dos.writeUTF(txt.getMenuText());
            }
        }
    } catch (Exception ex) {
        throw new UnexpectedException(ex);
    }
}

From source file:tvbrowser.core.PluginLoader.java

/**
 * Saves the information of a plugin to disk, so it does not need to be loaded next time
 * @param pluginFile full plugin file name
 * @param proxy proxy of the plugin//w ww .java 2  s  .  com
 */
private void saveProxyInfo(File pluginFile, JavaPluginProxy proxy) {
    try {
        String proxyFileName = getProxyFileName(pluginFile);
        DataOutputStream out = new DataOutputStream(
                new BufferedOutputStream(new FileOutputStream(proxyFileName)));

        PluginInfo info = proxy.getInfo();
        out.writeUTF(info.getName());
        out.writeUTF(info.getAuthor());
        out.writeUTF(info.getDescription());
        String license = info.getLicense();
        if (license == null) {
            license = "";
        }
        out.writeUTF(license);

        info.getVersion().writeData(out); //write version

        out.writeUTF(proxy.getId());
        out.writeLong(pluginFile.length());
        out.writeUTF(proxy.getPluginFileName());
        out.close();
        // also store the plugin icon, if it is not yet available
        String iconFileName = getProxyIconFileName(pluginFile);
        File iconFile = new File(iconFileName);
        if (!iconFile.exists()) {
            Icon pluginIcon = proxy.getPluginIcon();
            if (pluginIcon != null && pluginIcon instanceof ImageIcon) {
                IOUtilities.writeImageIconToFile((ImageIcon) pluginIcon, "png", iconFile);
            }
        }
    } catch (Exception e) {
    }
}

From source file:bankingclient.ChonThaoTacFrame.java

public ChonThaoTacFrame(NewOrOldAccFrame acc) {
    initComponents();/* ww  w.  j  a va2  s.c om*/
    jTextField1.setText("");

    jLabel4.setVisible(false);
    jComboBox2.setVisible(false);
    jLabel2.setVisible(false);
    jLabel3.setVisible(false);
    jTextField1.setVisible(false);
    jBt_xn1.setVisible(false);
    jBt_xn2.setVisible(false);

    this.accList = null;
    this.cusList = null;
    this.noAcc = acc;
    this.tt = new Thong_Tin_TK(this);
    this.setVisible(false);

    jBt_xn1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (NumberUtils.isNumber(jTextField1.getText()) && (Long.parseLong(jTextField1.getText()) > 0)) {
                long currentMoney = 0;
                try {
                    Socket client = new Socket("113.22.46.207", 6013);

                    DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                    dout.writeByte(8);
                    dout.writeUTF((String) jComboBox1.getSelectedItem());
                    dout.flush();

                    DataInputStream din = new DataInputStream(client.getInputStream());
                    Scanner lineScanner = new Scanner(din.readUTF());
                    currentMoney = Long.parseLong(lineScanner.nextLine());
                    System.out.println(currentMoney);

                } catch (Exception ex) {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(rootPane,
                            "Li kt ni mng,bn cn kim tra kt ni");
                }

                if (jCheck_gt.isSelected()) {
                    try {
                        Socket client = new Socket("113.22.46.207", 6013);
                        DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                        dout.writeByte(5);
                        dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n" + jTextField1.getText()
                                + "\n" + (noAcc.getCustomer()));
                        dout.flush();

                    } catch (Exception ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Xy ra....");
                    }
                    JOptionPane.showMessageDialog(rootPane, "Gi Ti?n Thnh Cng...");
                }

                if (jCheck_rt.isSelected()) {
                    if ((Long.parseLong(jTextField1.getText()) <= currentMoney)) {
                        try {
                            Socket client = new Socket("113.22.46.207", 6013);
                            DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                            dout.writeByte(6);
                            dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n" + jTextField1.getText()
                                    + "\n" + (noAcc.getCustomer()));
                            dout.flush();

                        } catch (Exception ex) {
                            ex.printStackTrace();
                            JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Xy Ra.....");
                        }
                        JOptionPane.showMessageDialog(rootPane, "Rt Ti?n Thnh Cng ...");
                    } else {
                        System.out.println("Khng  Ti?n Trong ti khon.." + currentMoney);
                        JOptionPane.showMessageDialog(null, "Ti Khon Khng ? ? Rt ...");
                    }
                }

                noAcc.setVisible(true);
                ChonThaoTacFrame.this.setVisible(false);
            } else {
                JOptionPane.showMessageDialog(rootPane,
                        "Cn Nhp Li S Ti?n Cn Gi Hoc Rt..");
            }

        }
    });

    jBt_tt.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tt.setTk((String) jComboBox1.getSelectedItem());
            tt.hienTenTk();
            long currentMoney = 0;
            try {
                Socket client = new Socket("113.22.46.207", 6013);

                DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                dout.writeByte(8);
                dout.writeUTF((String) jComboBox1.getSelectedItem());
                dout.flush();

                DataInputStream din = new DataInputStream(client.getInputStream());
                Scanner lineScanner = new Scanner(din.readUTF());
                currentMoney = Long.parseLong(lineScanner.nextLine());
                //                    System.out.println(currentMoney);

            } catch (Exception ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(rootPane,
                        "Li kt ni mng,bn cn kim tra kt ni");
            }
            tt.hienSoDu(((Long) currentMoney).toString());
            tt.setVisible(true);
            try {
                Socket client = new Socket("113.22.46.207", 6013);

                DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                dout.writeByte(10);
                dout.writeUTF((String) jComboBox1.getSelectedItem());
                dout.flush();

                DataInputStream din = new DataInputStream(client.getInputStream());
                Scanner cusScanner = new Scanner(din.readUTF());
                while (cusScanner.hasNextLine()) {
                    tt.addCus(cusScanner.nextLine());
                }
            } catch (Exception ee) {
                ee.printStackTrace();
            }
            tt.hienChuTaiKhoan();
            try {
                Socket client = new Socket("113.22.46.207", 6013);
                DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                dout.writeByte(12);
                dout.writeUTF((String) jComboBox1.getSelectedItem());
                dout.flush();

                DataInputStream din = new DataInputStream(client.getInputStream());
                Scanner dateScanner = new Scanner(din.readUTF());
                int day = Integer.parseInt(dateScanner.nextLine());
                int month = Integer.parseInt(dateScanner.nextLine());
                int year = Integer.parseInt(dateScanner.nextLine());
                String date = (day + "-" + month + "-" + year);
                tt.hienNgayLapTaiKhoan(date);
                while (dateScanner.hasNextLine()) {
                    //                        System.out.println("aaa");
                    tt.addGiaoDich(dateScanner.nextLine());
                }
                tt.hienGiaoDich();
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            ChonThaoTacFrame.this.setVisible(false);
        }
    });

    jBt_xn2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (jCheck_tctk.isSelected()) {
                try {
                    Socket client = new Socket("113.22.46.207", 6013);
                    DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                    dout.writeByte(7);
                    dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n"
                            + (String) jComboBox2.getSelectedItem());
                    dout.flush();
                } catch (Exception ex) {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(rootPane,
                            "C Li Kt Ni Xy Ra\n Thm Ch Tht Bi...");
                }
                JOptionPane.showMessageDialog(rootPane, "Thm Ch Ti Khon Thnh Cng..");
            } else {
                System.out.println("nothing to do...");
            }
        }
    });

    jBt_xtk.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Socket client = new Socket("113.22.46.207", 6013);
                DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                dout.writeByte(11);
                String sent = (String) (jComboBox1.getSelectedItem()) + "\n" + noAcc.getCustomer();
                dout.writeUTF(sent);
                dout.flush();
                DataInputStream din = new DataInputStream(client.getInputStream());
                byte check = din.readByte();
                if (check == 1) {
                    JOptionPane.showMessageDialog(rootPane, "xoa tai khoan thanh cong");
                } else {
                    JOptionPane.showMessageDialog(rootPane,
                            "<html>xoa tai khoan <b>khong</b> thanh cong <br> chi chu chinh moi co the xoa tai khoan</html>");
                }

            } catch (Exception ee) {
                ee.printStackTrace();
                JOptionPane.showMessageDialog(rootPane, "Li Kt Ni ,Vui Lng Kim Tra Li..");
            }
        }
    });

    /*dont touch*/
    jBt_ql.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            noAcc.setVisible(true);
            ChonThaoTacFrame.this.setVisible(false);
        }
    });
    /*dont touch*/

    jComboBox1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

        }
    });

    jComboBox2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

        }
    });

    /*dont touch jcheckbox*/
    jCheck_tctk.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (jCheck_tctk.isSelected()) {
                jLabel4.setVisible(true);
                jComboBox2.setVisible(true);
                jBt_xn2.setVisible(true);
            } else {
                jLabel4.setVisible(false);
                jComboBox2.setVisible(false);
                jBt_xn2.setVisible(false);
            }
        }
    });
    jCheck_gt.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (jCheck_gt.isSelected()) {
                if (jCheck_rt.isSelected()) {
                    jCheck_rt.setSelected(false);
                }
                jLabel2.setVisible(true);
                jLabel3.setVisible(true);
                jTextField1.setVisible(true);
                jBt_xn1.setVisible(true);
            } else {
                jLabel2.setVisible(false);
                jLabel3.setVisible(false);
                jTextField1.setVisible(false);
                jBt_xn1.setVisible(false);
            }
        }
    });
    jCheck_rt.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (jCheck_rt.isSelected()) {
                if (jCheck_gt.isSelected()) {
                    jCheck_gt.setSelected(false);
                }
                jLabel2.setVisible(true);
                jLabel3.setVisible(true);
                jTextField1.setVisible(true);
                jBt_xn1.setVisible(true);
            } else {
                jLabel2.setVisible(false);
                jLabel3.setVisible(false);
                jTextField1.setVisible(false);
                jBt_xn1.setVisible(false);
            }
        }
    });
    /*dont touch jcheckbox*/
}

From source file:hudson.cli.CLI.java

/**
 * @deprecated Specific to {@link Mode#REMOTING}.
 *///from w  ww  . ja va2 s  .  c o  m
@Deprecated
private Channel connectViaCliPort(URL jenkins, CliPort clip) throws IOException {
    LOGGER.log(FINE, "Trying to connect directly via Remoting over TCP/IP to {0}", clip.endpoint);

    if (authorization != null) {
        LOGGER.warning("-auth ignored when using JNLP agent port");
    }

    final Socket s = new Socket();
    // this prevents a connection from silently terminated by the router in between or the other peer
    // and that goes without unnoticed. However, the time out is often very long (for example 2 hours
    // by default in Linux) that this alone is enough to prevent that.
    s.setKeepAlive(true);
    // we take care of buffering on our own
    s.setTcpNoDelay(true);
    OutputStream out;

    if (httpsProxyTunnel != null) {
        String[] tokens = httpsProxyTunnel.split(":");
        LOGGER.log(Level.FINE, "Using HTTP proxy {0}:{1} to connect to CLI port",
                new Object[] { tokens[0], tokens[1] });
        s.connect(new InetSocketAddress(tokens[0], Integer.parseInt(tokens[1])));
        PrintStream o = new PrintStream(s.getOutputStream());
        o.print("CONNECT " + clip.endpoint.getHostString() + ":" + clip.endpoint.getPort()
                + " HTTP/1.0\r\n\r\n");

        // read the response from the proxy
        ByteArrayOutputStream rsp = new ByteArrayOutputStream();
        while (!rsp.toString("ISO-8859-1").endsWith("\r\n\r\n")) {
            int ch = s.getInputStream().read();
            if (ch < 0)
                throw new IOException("Failed to read the HTTP proxy response: " + rsp);
            rsp.write(ch);
        }
        String head = new BufferedReader(new StringReader(rsp.toString("ISO-8859-1"))).readLine();

        if (head == null) {
            throw new IOException("Unexpected empty response");
        }
        if (!(head.startsWith("HTTP/1.0 200 ") || head.startsWith("HTTP/1.1 200 "))) {
            s.close();
            LOGGER.log(Level.SEVERE,
                    "Failed to tunnel the CLI port through the HTTP proxy. Falling back to HTTP.");
            throw new IOException("Failed to establish a connection through HTTP proxy: " + rsp);
        }

        // HTTP proxies (at least the one I tried --- squid) doesn't seem to do half-close very well.
        // So instead of relying on it, we'll just send the close command and then let the server
        // cut their side, then close the socket after the join.
        out = new SocketOutputStream(s) {
            @Override
            public void close() throws IOException {
                // ignore
            }
        };
    } else {
        s.connect(clip.endpoint, 3000);
        out = SocketChannelStream.out(s);
    }

    closables.add(new Closeable() {
        public void close() throws IOException {
            s.close();
        }
    });

    Connection c = new Connection(SocketChannelStream.in(s), out);

    switch (clip.version) {
    case 1:
        DataOutputStream dos = new DataOutputStream(s.getOutputStream());
        dos.writeUTF("Protocol:CLI-connect");
        // we aren't checking greeting from the server here because I'm too lazy. It gets ignored by Channel constructor.
        break;
    case 2:
        DataInputStream dis = new DataInputStream(s.getInputStream());
        dos = new DataOutputStream(s.getOutputStream());
        dos.writeUTF("Protocol:CLI2-connect");
        String greeting = dis.readUTF();
        if (!greeting.equals("Welcome"))
            throw new IOException("Handshaking failed: " + greeting);
        try {
            byte[] secret = c.diffieHellman(false).generateSecret();
            SecretKey sessionKey = new SecretKeySpec(Connection.fold(secret, 128 / 8), "AES");
            c = c.encryptConnection(sessionKey, "AES/CFB8/NoPadding");

            // validate the instance identity, so that we can be sure that we are talking to the same server
            // and there's no one in the middle.
            byte[] signature = c.readByteArray();

            if (clip.identity != null) {
                Signature verifier = Signature.getInstance("SHA1withRSA");
                verifier.initVerify(clip.getIdentity());
                verifier.update(secret);
                if (!verifier.verify(signature))
                    throw new IOException("Server identity signature validation failed.");
            }

        } catch (GeneralSecurityException e) {
            throw (IOException) new IOException("Failed to negotiate transport security").initCause(e);
        }
    }

    return new Channel("CLI connection to " + jenkins, pool, new BufferedInputStream(c.in),
            new BufferedOutputStream(c.out));
}

From source file:com.p2p.misc.DeviceUtility.java

private void WriteData(OutputStream out, int cid, int lac) throws IOException {
    DataOutputStream dataOutputStream = new DataOutputStream(out);
    dataOutputStream.writeShort(21);/* w  ww  .  j  a  va  2s.  c o m*/
    dataOutputStream.writeLong(0);
    dataOutputStream.writeUTF("en");
    dataOutputStream.writeUTF("Android");
    dataOutputStream.writeUTF("1.0");
    dataOutputStream.writeUTF("Mobile");
    dataOutputStream.writeByte(27);
    dataOutputStream.writeInt(0);
    dataOutputStream.writeInt(0);
    dataOutputStream.writeInt(3);
    dataOutputStream.writeUTF("");

    dataOutputStream.writeInt(cid);
    dataOutputStream.writeInt(lac);

    dataOutputStream.writeInt(0);
    dataOutputStream.writeInt(0);
    dataOutputStream.writeInt(0);
    dataOutputStream.writeInt(0);
    dataOutputStream.flush();
}

From source file:org.prorefactor.refactor.PUB.java

private void writeExportSegment(DataOutputStream out, List rootSymbols) throws IOException {
    for (Iterator it = rootSymbols.iterator(); it.hasNext();) {
        Symbol symbol = (Symbol) it.next();
        if (symbol.isExported())
            writeSymbol(out, symbol);//from w  w w  .  j a  va2s.  c om
    }
    out.writeInt(-1);
    out.writeUTF("");
}

From source file:org.prorefactor.refactor.PUB.java

private void writeImportSegment(DataOutputStream out, List rootSymbols) throws IOException {
    for (Iterator it = rootSymbols.iterator(); it.hasNext();) {
        Symbol symbol = (Symbol) it.next();
        if (symbol.isImported())
            writeSymbol(out, symbol);//from   w ww.j  av a 2  s . co  m
    }
    out.writeInt(-1);
    out.writeUTF("");
}

From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java

/**
 * Serializes a <code>PropertyState</code> to the data output stream
 *
 * @param out the output stream//www.  j  av a  2 s.  c om
 * @param state the property entry to store
 * @throws IOException if an I/O error occurs.
 */
public void writeState(DataOutputStream out, NodePropBundle.PropertyEntry state) throws IOException {
    // type & mod count
    out.writeInt(state.getType() | (state.getModCount() << 16));
    // multiValued
    out.writeBoolean(state.isMultiValued());
    // definitionId
    out.writeUTF("");
    // values
    InternalValue[] values = state.getValues();
    out.writeInt(values.length); // count
    for (int i = 0; i < values.length; i++) {
        InternalValue val = values[i];
        switch (state.getType()) {
        case PropertyType.BINARY:
            BLOBFileValue blobVal = val.getBLOBFileValue();
            long size = blobVal.getLength();
            if (InternalValue.USE_DATA_STORE && dataStore != null) {
                int maxMemorySize = dataStore.getMinRecordLength() - 1;
                if (size < maxMemorySize) {
                    writeSmallBinary(out, blobVal, state, i);
                } else {
                    out.writeInt(BINARY_IN_DATA_STORE);
                    try {
                        val.store(dataStore);
                    } catch (RepositoryException e) {
                        String msg = "Error while storing blob. id=" + state.getId() + " idx=" + i + " size="
                                + val.getBLOBFileValue().getLength();
                        log.error(msg, e);
                        throw new IOException(msg);
                    }
                    out.writeUTF(val.toString());
                }
                break;
            }
            // special handling required for binary value:
            // spool binary value to file in blob store
            if (size < 0) {
                log.warn("Blob has negative size. Potential loss of data. " + "id={} idx={}", state.getId(),
                        String.valueOf(i));
                out.writeInt(0);
                values[i] = InternalValue.create(new byte[0]);
                blobVal.discard();
            } else if (size > minBlobSize) {
                out.writeInt(BINARY_IN_BLOB_STORE);
                String blobId = state.getBlobId(i);
                if (blobId == null) {
                    try {
                        InputStream in = blobVal.getStream();
                        try {
                            blobId = blobStore.createId(state.getId(), i);
                            blobStore.put(blobId, in, size);
                            state.setBlobId(blobId, i);
                        } finally {
                            IOUtils.closeQuietly(in);
                        }
                    } catch (Exception e) {
                        String msg = "Error while storing blob. id=" + state.getId() + " idx=" + i + " size="
                                + size;
                        log.error(msg, e);
                        throw new IOException(msg);
                    }
                    try {
                        // replace value instance with value
                        // backed by resource in blob store and delete temp file
                        if (blobStore instanceof ResourceBasedBLOBStore) {
                            values[i] = InternalValue
                                    .create(((ResourceBasedBLOBStore) blobStore).getResource(blobId));
                        } else {
                            values[i] = InternalValue.create(blobStore.get(blobId));
                        }
                    } catch (Exception e) {
                        log.error("Error while reloading blob. truncating. id=" + state.getId() + " idx=" + i
                                + " size=" + size, e);
                        values[i] = InternalValue.create(new byte[0]);
                    }
                    blobVal.discard();
                }
                // store id of blob as property value
                out.writeUTF(blobId); // value
            } else {
                // delete evt. blob
                byte[] data = writeSmallBinary(out, blobVal, state, i);
                // replace value instance with value
                // backed by resource in blob store and delete temp file
                values[i] = InternalValue.create(data);
                blobVal.discard();
            }
            break;
        case PropertyType.DOUBLE:
            out.writeDouble(val.getDouble());
            break;
        case PropertyType.LONG:
            out.writeLong(val.getLong());
            break;
        case PropertyType.BOOLEAN:
            out.writeBoolean(val.getBoolean());
            break;
        case PropertyType.NAME:
            writeQName(out, val.getQName());
            break;
        case PropertyType.REFERENCE:
            writeUUID(out, val.getUUID());
            break;
        default:
            // because writeUTF(String) has a size limit of 64k,
            // we're using write(byte[]) instead
            byte[] bytes = val.toString().getBytes("UTF-8");
            out.writeInt(bytes.length); // length of byte[]
            out.write(bytes); // byte[]
        }
    }
}