Package org.eclipse.emf.ecore.resource

Examples of org.eclipse.emf.ecore.resource.URIConverter$ReadableInputStream


    @SuppressWarnings("unchecked")
    private static URI createNewResource(Resource projectResource, String projectPath,
            ProjectElement projectElement) {
        int i = 0;
        List<Resource> list = projectResource.getResourceSet().getResources();
        URIConverter uriConverter = projectResource.getResourceSet().getURIConverter();
        URI uri = null;
        boolean found = false;
        do {
            found = false;
            i++;
            //TODO Add file extension name to ProjectElement
            uri = generateResourceName(projectPath, projectElement, i);

            URI normalizedURI = uriConverter.normalize(uri);
            for (Resource resource2 : list) {
                if (uriConverter.normalize(resource2.getURI()).equals(normalizedURI)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
View Full Code Here


       
        return resource;
      }
    }

    URIConverter theURIConverter = getURIConverter();
    URI normalizedURI = theURIConverter.normalize(uri);
   
    Iterator<Resource> it = getResources().iterator();
    while (it.hasNext()) {
      Resource resource = it.next();     
      if (theURIConverter.normalize(resource.getURI()).equals(
          normalizedURI)) {
        if (loadOnDemand && !resource.isLoaded()) {
          demandLoadHelper(resource);
        }
View Full Code Here

  public void resourceChanged (IFile file) {
               
    // System.out.println("ResourceChanged: " + file  );
    URI uri = URI.createPlatformResourceURI( file.getFullPath().toString() ) ;   
    // System.out.println("    ResourceURI: " + uri );   
    URIConverter theURIConverter = getURIConverter();
    URI normalizedURI = theURIConverter.normalize(uri);
       
    if (uriResourceMap != null) {
      uriResourceMap.remove(uri);
      uriResourceMap.remove(normalizedURI);
      // System.out.println("Removed from Map: " + map );
View Full Code Here

      Map<?, ?> response = options == null ? null : (Map<?, ?>)options.get(URIConverter.OPTION_RESPONSE);
      if (response == null)
      {
        response = new HashMap<Object, Object>();
      }
      URIConverter uriConverter = getURIConverter();
      OutputStream outputStream = uriConverter.createOutputStream(getURI(), new ExtensibleURIConverterImpl.OptionsMap(URIConverter.OPTION_RESPONSE, response, options));
      try
      {
        save(outputStream, options);
      }
      finally
View Full Code Here

  {
    File temporaryFile = File.createTempFile("ResourceSaveHelper", null);
    try
    {
      URI temporaryFileURI = URI.createFileURI(temporaryFile.getPath());
      URIConverter uriConverter = getURIConverter();
      OutputStream temporaryFileOutputStream = uriConverter.createOutputStream(temporaryFileURI, null);
      try
      {
        save(temporaryFileOutputStream, options);
      }
      finally
      {
        temporaryFileOutputStream.close();
      }

      boolean equal = true;
      InputStream oldContents = null;
      try
      {
        oldContents = getUnderlyingInputStream(uriConverter.createInputStream(getURI(), defaultLoadOptions), options);
      }
      catch (IOException exception)
      {
        equal = false;
      }
      byte [] newContentBuffer = new byte [4000];
      if (oldContents != null)
      {
        try
        {
          InputStream newContents = getUnderlyingInputStream(uriConverter.createInputStream(temporaryFileURI, null), options);
          try
          {
            byte [] oldContentBuffer = new byte [4000];
            LOOP:
            for (int oldLength = oldContents.read(oldContentBuffer), newLength = newContents.read(newContentBuffer);
                 (equal = oldLength == newLength) &&  oldLength > 0;
                 oldLength = oldContents.read(oldContentBuffer), newLength = newContents.read(newContentBuffer))
            {
              for (int i = 0; i < oldLength; ++i)
              {
                if (oldContentBuffer[i] != newContentBuffer[i])
                {
                  equal = false;
                  break LOOP;
                }
              }
            }
          }
          finally
          {
            newContents.close();
          }
        }
        finally
        {
          oldContents.close();
        }
      }

      if (!equal)
      {
        Map<?, ?> response = options == null ? null : (Map<?, ?>)options.get(URIConverter.OPTION_RESPONSE);
        if (response == null)
        {
          response = new HashMap<Object, Object>();
        }
        OutputStream newContents = uriConverter.createOutputStream(getURI(), new ExtensibleURIConverterImpl.OptionsMap(URIConverter.OPTION_RESPONSE, response, options));
        try
        {
          InputStream temporaryFileContents = uriConverter.createInputStream(temporaryFileURI, null);
          try
          {
            for (int length = temporaryFileContents.read(newContentBuffer); length > 0; length = temporaryFileContents.read(newContentBuffer))
            {
              newContents.write(newContentBuffer, 0, length);
View Full Code Here

    }
  }

  protected void saveOnlyIfChangedWithMemoryBuffer(Map<?, ?> options) throws IOException
  {
    URIConverter uriConverter = getURIConverter();
    class MyByteArrayOutputStream extends ByteArrayOutputStream
    {
      public byte[] buffer()
      {
        return buf;
      }

      public int length()
      {
        return count;
      }
    }
    MyByteArrayOutputStream memoryBuffer = new MyByteArrayOutputStream();
    try
    {
      save(memoryBuffer, options);
    }
    finally
    {
      memoryBuffer.close();
    }

    byte [] newContentBuffer = memoryBuffer.buffer();
    int length = memoryBuffer.length();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(newContentBuffer);
    InputStream underlyingInputStream = getUnderlyingInputStream(inputStream, options);
    byte [] underlyingNewContentBuffer;
    int underlyingLength;
    if (inputStream == underlyingInputStream)
    {
      underlyingNewContentBuffer = newContentBuffer;
      underlyingLength = length;
    }
    else
    {
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      byte [] buffer = new byte[4000];
      for (int count = underlyingInputStream.read(buffer); count > 0; count = underlyingInputStream.read(buffer))
      {
        bytes.write(buffer, 0, count);
      }
      bytes.close();
      underlyingInputStream.close();
      underlyingNewContentBuffer = bytes.toByteArray();
      underlyingLength = underlyingNewContentBuffer.length;
    }

    boolean equal = true;
    InputStream oldContents = null;
    try
    {
      oldContents = getUnderlyingInputStream(uriConverter.createInputStream(getURI(), defaultLoadOptions), options);
    }
    catch (IOException exception)
    {
      equal = false;
    }
    if (oldContents != null)
    {
      try
      {
        byte [] oldContentBuffer = new byte [underlyingLength];
        int count = oldContents.read(oldContentBuffer);
        while (count > 0 && count < underlyingLength)
        {
          int more = oldContents.read(oldContentBuffer, count, oldContentBuffer.length - count);
          if (more <= 0)
          {
            break;
          }
          else
          {
            count += more;
          }
        }
        if (count == underlyingLength && oldContents.read() == -1)
        {
          for (int i = 0; i < underlyingLength; ++i)
          {
            if (oldContentBuffer[i] != underlyingNewContentBuffer[i])
            {
              equal = false;
              break;
            }
          }
        }
        else
        {
          equal = false;
        }
      }
      finally
      {
        oldContents.close();
      }
    }

    if (!equal)
    {
      Map<?, ?> response = options == null ? null : (Map<?, ?>)options.get(URIConverter.OPTION_RESPONSE);
      if (response == null)
      {
        response = new HashMap<Object, Object>();
      }
      OutputStream newContents = uriConverter.createOutputStream(getURI(), new ExtensibleURIConverterImpl.OptionsMap(URIConverter.OPTION_RESPONSE, response, options));
      try
      {
        newContents.write(newContentBuffer, 0, length);
      }
      finally
View Full Code Here

   */
  public void load(Map<?, ?> options) throws IOException
  {
    if (!isLoaded)
    {
      URIConverter uriConverter = getURIConverter();
      Map<?, ?> response = options == null ? null : (Map<?, ?>)options.get(URIConverter.OPTION_RESPONSE);
      if (response == null)
      {
        response = new HashMap<Object, Object>();
      }

      // If an input stream can't be created, ensure that the resource is still considered loaded after the failure,
      // and do all the same processing we'd do if we actually were able to create a valid input stream.
      //
      InputStream inputStream = null;
      try
      {
        inputStream =
          uriConverter.createInputStream
            (getURI(),
             new ExtensibleURIConverterImpl.OptionsMap(URIConverter.OPTION_RESPONSE, response, options));
      }
      catch (IOException exception)
      {
View Full Code Here

  /**
   * This implementation delegates to the {@link #getURIConverter(Map) URI converter}'s {@link URIConverter#getContentHandlers() content handlers}.
   */
  public Map<String, ?> contentDescription(URI uri, Map<?, ?> options) throws IOException
  {
    URIConverter uriConverter = (URIConverter)options.get(URIConverter.OPTION_URI_CONVERTER);
    InputStream inputStream = null;
    Map<String, ?> result = null;
    Map<Object, Object> context = new HashMap<Object, Object>();
    try
    {
      for (ContentHandler contentHandler : uriConverter.getContentHandlers())
      {
        if (contentHandler.canHandle(uri))
        {
          if (inputStream == null)
          {
View Full Code Here

        }
        return resource;
      }
    }

    URIConverter theURIConverter = getURIConverter();
    URI normalizedURI = theURIConverter.normalize(uri);
    for (Resource resource : getResources())
    {
      if (theURIConverter.normalize(resource.getURI()).equals(normalizedURI))
      {
        if (loadOnDemand && !resource.isLoaded())
        {
          demandLoadHelper(resource);
        }
View Full Code Here

      Map<?, ?> response = options == null ? null : (Map<?, ?>)options.get(URIConverter.OPTION_RESPONSE);
      if (response == null)
      {
        response = new HashMap<Object, Object>();
      }
      URIConverter uriConverter = getURIConverter();
      OutputStream outputStream = uriConverter.createOutputStream(getURI(), new ExtensibleURIConverterImpl.OptionsMap(URIConverter.OPTION_RESPONSE, response, options, defaultSaveOptions));
      try
      {
        save(outputStream, options);
      }
      finally
View Full Code Here

TOP

Related Classes of org.eclipse.emf.ecore.resource.URIConverter$ReadableInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.