|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.microedition.m2g.connection.file; |
|
19 |
|
20 import javax.microedition.io.file.FileConnection; |
|
21 import javax.microedition.io.Connector; |
|
22 import java.io.IOException; |
|
23 import com.nokia.microedition.m2g.connection.*; |
|
24 import com.nokia.mj.impl.utils.Logger; |
|
25 |
|
26 /** |
|
27 * File connection proxy class |
|
28 */ |
|
29 public class M2GConnectionProxyImpl extends M2GConnectionProxy |
|
30 { |
|
31 |
|
32 //-------------------------------------------------- |
|
33 // STATIC CONSTANTS |
|
34 //-------------------------------------------------- |
|
35 public static final String READ_PERMISSION = |
|
36 "javax.microedition.io.Connector.file.read"; |
|
37 |
|
38 //-------------------------------------------------- |
|
39 // METHODS |
|
40 //-------------------------------------------------- |
|
41 /** |
|
42 * Ctor. |
|
43 */ |
|
44 public M2GConnectionProxyImpl() |
|
45 { |
|
46 super(); |
|
47 } |
|
48 |
|
49 /** |
|
50 * Open a connection. |
|
51 * @see connection.common.M2GConnectionProxy#open() |
|
52 */ |
|
53 public void open(M2GUrlTokenizer aTokenizer) throws IOException |
|
54 { |
|
55 boolean openingStream = false; |
|
56 FileConnection connection = null; |
|
57 try |
|
58 { |
|
59 iBaseUrl = aTokenizer.getBaseUrl(); |
|
60 |
|
61 // extract the suffix url from the initial url used to open the |
|
62 // file, and not the constructed (altered in default mode) url by |
|
63 // M2GConnectionPolicyImpl. |
|
64 // This suffix is passed to the external resource handler later |
|
65 iSuffixUrl = aTokenizer.getParameters(); |
|
66 if (iSuffixUrl != null) |
|
67 { |
|
68 iSuffixUrl = M2GUrlTokenizer.PARAMETER_SEPARATOR + iSuffixUrl; |
|
69 } |
|
70 |
|
71 Logger.LOG( |
|
72 Logger.EJavaUI, |
|
73 Logger.EInfo, |
|
74 "file open(), suffix URI: " |
|
75 + (iSuffixUrl != null ? iSuffixUrl.toString() : "null") |
|
76 + ", create file connection - 0"); |
|
77 |
|
78 M2GConnectionPolicyImpl connectionPolicy = |
|
79 new M2GConnectionPolicyImpl(aTokenizer); |
|
80 |
|
81 String uri = aTokenizer.getUrl(); |
|
82 |
|
83 Logger.LOG( |
|
84 Logger.EJavaUI, |
|
85 Logger.EInfo, |
|
86 "file open(), URI: " + uri |
|
87 + ", create file connection - 2"); |
|
88 |
|
89 connection = (FileConnection) Connector.open(uri, |
|
90 Connector.READ); |
|
91 openingStream = true; |
|
92 iInputStream = connection.openInputStream(); |
|
93 openingStream = false; |
|
94 iConnection = connection; |
|
95 iConnectionPolicy = connectionPolicy; |
|
96 } |
|
97 finally |
|
98 { |
|
99 if ((true == openingStream) && (null != connection)) |
|
100 { |
|
101 connection.close(); |
|
102 } |
|
103 } |
|
104 } |
|
105 } |