Revision 20070

View differences:

trunk/libraries/libCompatMobile/src/org/gvsig/compat/StringUtils.java
1
package org.gvsig.compat;
2

  
3
import java.util.regex.Pattern;
4

  
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *   Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *   +34 963862235
32
 *   gvsig@gva.es
33
 *   http://www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   Prodevelop Integraci?n de Tecnolog?as SL
38
 *   Conde Salvatierra de ?lava , 34-10
39
 *   46004 Valencia
40
 *   Spain
41
 *
42
 *   +34 963 510 612
43
 *   +34 963 510 968
44
 *   gis@prodevelop.es
45
 *   http://www.prodevelop.es
46
 *
47
 *    or
48
 *
49
 *   Instituto de Rob?tica
50
 *   Apartado de correos 2085
51
 *   46071 Valencia
52
 *   (Spain)
53
 *   
54
 *   +34 963 543 577
55
 *   jjordan@robotica.uv.es
56
 *   http://robotica.uv.es
57
 *   
58
 */
59
/* CVS MESSAGES:
60
 * -------------
61
 * $Id$
62
 * $Log$
63
 *
64
 */
65
/****************************************************************
66
 *
67
 * StringUtils
68
 * This class includes some methods needed by gvSIG Mobile that the KVM
69
 * hasn't in "java.lang.String"
70
 *																
71
 * PRODEVELOP S.L.												
72
 * @author Carlos S?nchez Peri??n (csanchez@prodevelop.es)		
73
 *																
74
 ****************************************************************/
75
public class StringUtils {
76
	/*
77
	 * splitString(String,String) : static method compatible with java.lang.String.split(String sep)
78
	 */
79
	public static String[] splitString(String input, String sep) {
80
		return Pattern.compile(sep).split(input, 0);
81
	}
82

  
83
	/*
84
	 * splitChar(String,char)  :  static method similar to split() but only seek for a char to split beyond it
85
	 */
86
	public static String[] splitChar(String origin, char expresion){
87
		String ns[];
88
		String aux = origin;
89
		int indexFin;
90
		int indexStart=0;
91
		int i=0;
92
		
93
		//take the string in couples of words separates by :
94
		indexFin = origin.indexOf(expresion);
95
		if(indexFin!=-1){
96
			while (indexFin!=-1){
97
				aux = aux.substring(indexFin+1);
98
				indexFin = aux.indexOf(expresion);
99
				i++;
100
			}
101
			ns = new String[i+1];
102
			aux = origin;
103
			i=0;
104
			indexFin = aux.indexOf(expresion);
105
			while (indexFin!=-1){
106
				ns[i]= aux.substring(0,indexFin);
107
				indexStart=indexFin+1;
108
				aux = aux.substring(indexStart);
109
				indexFin = aux.indexOf(expresion);
110
				i++;
111
			}
112
			ns[i]=aux;	
113
		}
114
		else
115
		{
116
			ns = new String[1];
117
			ns[0] = origin;
118
		}
119
		return ns;
120
	}
121
	
122
	/*
123
	 * replaceAllString(String,String,String)  :  static method similar to replaceAllt() by java.lang.String.replaceAll(String,String)
124
	 */
125
	public static String replaceAllString(String original, String match_old,
126
			String match_new) {
127
		return Pattern.compile(match_old).matcher(original).replaceAll(
128
				match_new);
129
	}
130
}
trunk/libraries/libCompatMobile/src/org/gvsig/compat/FileUtils.java
1
package org.gvsig.compat;
2

  
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.nio.ByteBuffer;
6
import java.nio.channels.FileChannel;
7

  
8
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
9
 *
10
 * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
11
 *
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
25
 *
26
 * For more information, contact:
27
 *
28
 *   Generalitat Valenciana
29
 *   Conselleria d'Infraestructures i Transport
30
 *   Av. Blasco Ib??ez, 50
31
 *   46010 VALENCIA
32
 *   SPAIN
33
 *
34
 *   +34 963862235
35
 *   gvsig@gva.es
36
 *   http://www.gvsig.gva.es
37
 *
38
 *    or
39
 *
40
 *   Prodevelop Integraci?n de Tecnolog?as SL
41
 *   Conde Salvatierra de ?lava , 34-10
42
 *   46004 Valencia
43
 *   Spain
44
 *
45
 *   +34 963 510 612
46
 *   +34 963 510 968
47
 *   gis@prodevelop.es
48
 *   http://www.prodevelop.es
49
 *
50
 *    or
51
 *
52
 *   Instituto de Rob?tica
53
 *   Apartado de correos 2085
54
 *   46071 Valencia
55
 *   (Spain)
56
 *   
57
 *   +34 963 543 577
58
 *   jjordan@robotica.uv.es
59
 *   http://robotica.uv.es
60
 *   
61
 */
62
/* CVS MESSAGES:
63
 * -------------
64
 * $Id$
65
 * $Log$
66
 *
67
 */
68
/****************************************************************
69
 *																*
70
 * PRODEVELOP S.L.												*
71
 * @author Carlos S?nchez Peri??n (csanchez@prodevelop.es)		*
72
 *																*
73
 ****************************************************************/
74
public class FileUtils {
75

  
76
    public static byte[] readFile(File f){
77
    	byte[] data = null;
78
    	try{
79
	        FileInputStream fis = new FileInputStream(f);
80
	        FileChannel fc = fis.getChannel();
81
	        data=  new byte[(int)fc.size()];   // fc.size returns the size of the file which backs the channel
82
	        ByteBuffer bb = ByteBuffer.wrap(data);
83
	        fc.read(bb);
84
    	} catch (Exception e){
85
    		
86
    	}
87
        return data;
88
    }
89
}

Also available in: Unified diff