Project

General

Profile

« Previous | Next » 

Revision 2261

Added by sgarg almost 20 years ago

Added method to metacat client for reading inline data - readInlineData()

View differences:

src/edu/ucsb/nceas/metacat/client/MetacatClient.java
186 186
        return pbr;
187 187
    }
188 188

  
189

  
189 190
    /**
191
        * Read inline data from the metacat server session, accessed by
192
        * inlinedataid and returned as a Reader.
193
        *
194
        * @param inlinedataid the identifier of the data to be read
195
        * @return a Reader for accessing the document
196
        * @throws InsufficientKarmaException when the user has insufficent rights
197
        *                                    for the operation
198
        * @throws MetacatInaccessibleException when the metacat server can not be
199
        *                                    reached or does not respond
200
        * @throws MetacatException when the metacat server generates another error
201
        */
202
       public Reader readInlineData(String inlinedataid)
203
           throws InsufficientKarmaException,
204
           MetacatInaccessibleException, MetacatException
205
       {
206
           PushbackReader pbr = null;
207

  
208
           Properties prop = new Properties();
209
           prop.put("action", "readinlinedata");
210
           prop.put("inlinedataid", inlinedataid);
211

  
212
           InputStream response = null;
213
           try {
214
               response = sendData(prop, null);
215
           } catch (Exception e) {
216
               throw new MetacatInaccessibleException(e.getMessage());
217
           }
218

  
219
           pbr = new PushbackReader(new InputStreamReader(response), 512);
220
           try {
221
               char[] characters = new char[512];
222
               int len = pbr.read(characters, 0, 512);
223
               StringWriter sw = new StringWriter();
224
               sw.write(characters, 0, len);
225
               String message = sw.toString();
226
               sw.close();
227
               pbr.unread(characters, 0, len);
228

  
229
               if (message.indexOf("<error>") != -1) {
230
                   if (message.indexOf("does not have permission") != -1) {
231
                       throw new InsufficientKarmaException(message);
232
                   } else {
233
                       throw new MetacatException(message);
234
                   }
235
               }
236
           } catch (IOException ioe) {
237
               throw new MetacatException(
238
                       "MetacatClient: Error converting Reader to String."
239
                       + ioe.getMessage());
240
           }
241

  
242
           return pbr;
243
       }
244

  
245
    /**
190 246
     * Query the metacat document store with the given metacat-compatible
191 247
     * query document, and return the result set as a Reader.
192 248
     *
src/edu/ucsb/nceas/metacat/client/Metacat.java
77 77
        MetacatInaccessibleException, MetacatException;
78 78

  
79 79
    /**
80
     * Read inline data from the metacat server session, accessed by
81
     * inlinedataid, and returned as a Reader.
82
     *
83
     * @param inlinedataid the identifier of the document to be read
84
     * @return a Reader for accessing the document
85
     * @throws InsufficientKarmaException when the user has insufficent rights
86
     *                                    for the operation
87
     * @throws MetacatInaccessibleException when the metacat server can not be
88
     *                                    reached or does not respond
89
     * @throws MetacatException when the metacat server generates another error
90
     */
91
    public Reader readInlineData(String inlinedataid)
92
        throws InsufficientKarmaException,
93
        MetacatInaccessibleException, MetacatException;
94

  
95
    /**
80 96
     * Query the metacat document store with the given metacat-compatible
81 97
     * query document, and return the result set as a Reader.
82 98
     *

Also available in: Unified diff