Statistics
| Revision:

root / trunk / libraries / libGDBMS / src / main / java / com / hardcode / gdbms / driver / DriverUtilities.java @ 3556

History | View | Annotate | Download (2.54 KB)

1
/*
2
 * Created on 15-sep-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 
21
 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
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45

    
46
/* CVS MESSAGES:
47
 * 
48
 * $Id: DriverUtilities.java 3556 2006-01-09 18:18:20Z fjp $
49
 * $Log$
50
 * Revision 1.2  2006-01-09 18:15:06  fjp
51
 * Solucionar un fallo detectado por Jaume que hac?a que no se escribieran archivos de m?s de 100 KBytes.
52
 *
53
 */
54
package com.hardcode.gdbms.driver;
55

    
56
import java.io.IOException;
57
import java.nio.ByteBuffer;
58
import java.nio.channels.FileChannel;
59

    
60
/**
61
 * Utility method for the drivers
62
 */
63
public class DriverUtilities {
64
    /**
65
     * Copies the contents of the fcin FileChannel to the fcout FileChannel
66
     * 
67
     * @param fcin
68
     * @param fcout
69
     * 
70
     * @throws IOException
71
     */
72
    public static void copy(FileChannel fcin, FileChannel fcout)
73
            throws IOException {
74
        
75
        // Esto antes ten?a un problema de que solo copiaba
76
        // los primeros 100 KBytes. Ahora le hemos puesto
77
        // un while y hemos comprobado que copia todo el fichero.
78
        // Ole tus huevos Luis, que tenga que comentar esto
79
        // y ver c?mo est? el resto del c?digo.
80
        ByteBuffer buffer = ByteBuffer.allocate(102400);
81
        buffer.clear();
82
        int r = 0;
83
        int position = 0;
84
        while ((r = fcin.read(buffer, position)) != -1)
85
        {
86
            buffer.flip();
87
            int bytesWritten = fcout.write(buffer, position);
88
            position += bytesWritten;
89
            buffer.clear();
90
        }
91
    }
92
    
93
}