Android Open Source - android-tao-rest-data-processor Assets Request






From Project

Back to project page android-tao-rest-data-processor.

License

The source code is released under:

/******************************************************************************* * Copyright (c) 2014 Alexandr Tsvetkov. * All rights reserved. This program and the accompanying materials * are mad...

If you think the Android project android-tao-rest-data-processor listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * Copyright (c) 2014 Alexandr Tsvetkov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *// w  w  w  .  jav a  2 s .  com
 * Contributors:
 *     Alexandr Tsvetkov - initial API and implementation
 *
 * Project:
 *     TAO Data Processor
 *
 * License agreement:
 *
 * 1. This code is published AS IS. Author is not responsible for any damage that can be
 *    caused by any application that uses this code.
 * 2. Author does not give a garantee, that this code is error free.
 * 3. This code can be used in NON-COMMERCIAL applications AS IS without any special
 *    permission from author.
 * 4. This code can be modified without any special permission from author IF AND ONLY IF
 *    this license agreement will remain unchanged.
 ******************************************************************************/
package ua.at.tsvetkov.data_processor.requests;

import java.io.IOException;
import java.io.InputStream;

import ua.at.tsvetkov.data_processor.ProcessingCentre;
import android.content.Context;
import android.content.res.AssetManager;

/**
 * The main class for the assets file request building. If not specified the request be built with basic configuration parameters specified
 * in {@link ua.at.tsvetkov.data_processor.DataProcessorConfiguration DataProcessorConfiguration}.
 * 
 * @author lordtao
 */
public class AssetsRequest extends Request {

   private InputStream  inputStream;
   private AssetManager assetManager;

   public AssetsRequest(Context context) {
      assetManager = context.getAssets();
   }

   /**
    * Return new instance of AssetsRequest.
    * 
    * @return
    */
   public static AssetsRequest newInstance(Context context) {
      return new AssetsRequest(context);
   }

   /*
    * (non-Javadoc)
    * @see ua.at.tsvetkov.data_processor.requests.Request#getInputStream()
    */
   @Override
   public InputStream getInputStream() throws IOException {
      if (!isBuild())
         throw new IllegalArgumentException(REQUEST_IS_NOT_BUILDED);

      printToLogUrl();

      startTime = System.currentTimeMillis();

      inputStream = assetManager.open(toString());
      statusCode = ProcessingCentre.FILE_SUCCESS;
      return inputStream;
   }

   /**
    * Set path
    * 
    * @param url
    */
   public AssetsRequest setPath(String path) {
      this.path = path;
      return this;
   }

   /**
    * Set full path
    * 
    * @param url
    */
   public AssetsRequest setFullPath(String path) {
      this.url = path;
      return this;
   }

   /**
    * Release resources associated with this request. You must call this, or significant resources (sockets and memory) may be leaked.
    */
   @Override
   public void close() throws Exception {
      if (inputStream != null)
         inputStream.close();
   }

}




Java Source Code List

ua.at.tsvetkov.data_processor.DataProcessorConfiguration.java
ua.at.tsvetkov.data_processor.DataProcessor.java
ua.at.tsvetkov.data_processor.Encoding.java
ua.at.tsvetkov.data_processor.ProcessingCentre.java
ua.at.tsvetkov.data_processor.Scheme.java
ua.at.tsvetkov.data_processor.interfaces.InputStreamDataInterface.java
ua.at.tsvetkov.data_processor.interfaces.StringDataInterface.java
ua.at.tsvetkov.data_processor.processors.InputStreamProcessor.java
ua.at.tsvetkov.data_processor.processors.StringProcessor.java
ua.at.tsvetkov.data_processor.processors.abstractclasses.AbstractProcessor.java
ua.at.tsvetkov.data_processor.processors.abstractclasses.StringAbstractProcessor.java
ua.at.tsvetkov.data_processor.requests.AssetsRequest.java
ua.at.tsvetkov.data_processor.requests.DeleteRequest.java
ua.at.tsvetkov.data_processor.requests.FileRequest.java
ua.at.tsvetkov.data_processor.requests.GetRequest.java
ua.at.tsvetkov.data_processor.requests.MultipartRequest.java
ua.at.tsvetkov.data_processor.requests.PostRequest.java
ua.at.tsvetkov.data_processor.requests.PutRequest.java
ua.at.tsvetkov.data_processor.requests.Request.java
ua.at.tsvetkov.data_processor.requests.WebRequest.java