Java tutorial
//package com.java2s; /* * Copyright(c) 2005 Center for E-Commerce Infrastructure Development, The * University of Hong Kong (HKU). All Rights Reserved. * * This software is licensed under the GNU GENERAL PUBLIC LICENSE Version 2.0 [1] * * [1] http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt */ import java.io.UnsupportedEncodingException; public class Main { public final static String NAME_ENCODING = "UTF-8"; /** * Parse an entry name from a header buffer. * * @param header The header buffer from which to parse. * @param offset The offset into the buffer from which to parse. * @param length The number of header bytes to parse. * @return The header's entry name. */ public static StringBuffer parseName(byte[] header, int offset, int length) { StringBuffer result = null; int nameLen = length; int end = offset + length; for (int i = offset; i < end; ++i) { if (header[i] == 0) { nameLen = i - offset; break; } // result.append((char) header[i]); } try { result = new StringBuffer(new String(header, offset, nameLen, NAME_ENCODING)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return result; } }