KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > indexing > Convert


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.indexing;
12
13 import java.io.UnsupportedEncodingException JavaDoc;
14
15 class Convert {
16
17     /**
18      * Converts the string argument to a byte array.
19      */

20     static String JavaDoc fromUTF8(byte[] b) {
21         String JavaDoc result;
22         try {
23             result = new String JavaDoc(b, "UTF8"); //$NON-NLS-1$
24
} catch (UnsupportedEncodingException JavaDoc e) {
25             result = new String JavaDoc(b);
26         }
27         return result;
28     }
29
30     /**
31      * Converts the string argument to a byte array.
32      */

33     static byte[] toUTF8(String JavaDoc s) {
34         byte[] result;
35         try {
36             result = s.getBytes("UTF8"); //$NON-NLS-1$
37
} catch (UnsupportedEncodingException JavaDoc e) {
38             result = s.getBytes();
39         }
40         return result;
41     }
42 }
43
Popular Tags