Java ByteBuffer Put putString(ByteBuffer buf, String value)

Here you can find the source of putString(ByteBuffer buf, String value)

Description

put String

License

Open Source License

Declaration

private static void putString(ByteBuffer buf, String value) 

Method Source Code

//package com.java2s;
/*/*ww w . j  av a2 s.com*/
 This file is part of the Greenfoot program. 
 Copyright (C) 2005-2009,2010,2011,2012  Poul Henriksen and Michael Kolling 
    
 This program is free software; you can redistribute it and/or 
 modify it under the terms of the GNU General Public License 
 as published by the Free Software Foundation; either version 2 
 of the License, or (at your option) any later version. 
    
 This program is distributed in the hope that it will be useful, 
 but WITHOUT ANY WARRANTY; without even the implied warranty of 
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 GNU General Public License for more details. 
    
 You should have received a copy of the GNU General Public License 
 along with this program; if not, write to the Free Software 
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
    
 This file is subject to the Classpath exception as provided in the  
 LICENSE.txt file that accompanied this code.
 */

import java.nio.ByteBuffer;

public class Main {
    private static void putString(ByteBuffer buf, String value) {
        if (value == null) {
            buf.putShort((short) -1);
        } else {
            buf.putShort((short) value.length()); //2-bytes for length
            for (int i = 0; i < value.length(); i++) {
                buf.putChar(value.charAt(i));
            }
        }
    }
}

Related

  1. putRange(ByteBuffer buffer, int start, int end, byte b)
  2. putRGBfromHSB(final ByteBuffer pixels, final float[] hsb, int pixelSize)
  3. putStr(ByteBuffer buff, String str)
  4. putString(@Nullable final String s, @Nonnull final ByteBuffer dst)
  5. putString(ByteBuffer bb, String s)
  6. putString(ByteBuffer buffer, String s)
  7. putString(ByteBuffer buffer, String s)
  8. putString(final ByteBuffer buffer, final String string)
  9. putString(String name, ByteBuffer buffer)