Package org.eclipse.emf.ecore.resource

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


  {
    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, defaultSaveOptions));
        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, defaultSaveOptions));
      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, defaultLoadOptions));
      }
      catch (IOException exception)
      {
View Full Code Here

        String _plus_2 = (_string_1 + "/");
        String _replaceAll = fromRelativeFileName.replaceAll("\\.\\.", "");
        String _plus_3 = (_plus_2 + _replaceAll);
        final URI outPath = URI.createURI(_plus_3);
        ResourceSet _resourceSet = res.getResourceSet();
        URIConverter _uRIConverter = _resourceSet.getURIConverter();
        InputStream _createInputStream = _uRIConverter.createInputStream(inPath);
        final ReadableByteChannel inChannel = Channels.newChannel(_createInputStream);
        ResourceSet _resourceSet_1 = res.getResourceSet();
        URIConverter _uRIConverter_1 = _resourceSet_1.getURIConverter();
        OutputStream _createOutputStream = _uRIConverter_1.createOutputStream(outPath);
        final WritableByteChannel outChannel = Channels.newChannel(_createOutputStream);
        while ((new Function0<Integer>() {
          public Integer apply() {
            try {
              int _read = inChannel.read(buffer);
View Full Code Here

        String _plus = (_string + "/");
        String _plus_1 = (_plus + fromRelativeFileName);
        final URI inPath = URI.createURI(_plus_1);
        final URI outPath = this.accessExtension2.getURI(fromRelativeFileName, Outlets.ECLIPSE_HELP);
        ResourceSet _resourceSet = res.getResourceSet();
        URIConverter _uRIConverter = _resourceSet.getURIConverter();
        InputStream _createInputStream = _uRIConverter.createInputStream(inPath);
        final ReadableByteChannel inChannel = Channels.newChannel(_createInputStream);
        ResourceSet _resourceSet_1 = res.getResourceSet();
        URIConverter _uRIConverter_1 = _resourceSet_1.getURIConverter();
        OutputStream _createOutputStream = _uRIConverter_1.createOutputStream(outPath);
        final WritableByteChannel outChannel = Channels.newChannel(_createOutputStream);
        while ((new Function0<Integer>() {
          public Integer apply() {
            try {
              int _read = inChannel.read(buffer);
View Full Code Here

    try {
      final Resource res = imgRef.eResource();
      final ByteBuffer buffer = ByteBuffer.allocateDirect((16 * 1024));
      final URI uri = res.getURI();
      ResourceSet _resourceSet = res.getResourceSet();
      final URIConverter uriConverter = _resourceSet.getURIConverter();
      File _file = new File("");
      String _absolutePath = _file.getAbsolutePath();
      String _plus = (_absolutePath + "/");
      final URI absoluteLocalPath = URI.createFileURI(_plus);
      String _path = imgRef.getPath();
      final URI relativeImageURI = URI.createFileURI(_path);
      URI _resolve = relativeImageURI.resolve(uri);
      final URI inPath = _resolve.deresolve(absoluteLocalPath);
      List<String> _segmentsList = inPath.segmentsList();
      int _segmentCount = inPath.segmentCount();
      final List<String> inSegments = _segmentsList.subList(1, _segmentCount);
      final String pathInDocument = IterableExtensions.join(inSegments, "/");
      Object _get = this.config.get(Config.outletPath);
      String _string = _get.toString();
      String _plus_1 = (_string + "/");
      String _plus_2 = (_plus_1 + pathInDocument);
      final URI outPath = URI.createFileURI(_plus_2);
      InputStream _createInputStream = uriConverter.createInputStream(inPath);
      final ReadableByteChannel inChannel = Channels.newChannel(_createInputStream);
      ResourceSet _resourceSet_1 = res.getResourceSet();
      URIConverter _uRIConverter = _resourceSet_1.getURIConverter();
      OutputStream _createOutputStream = _uRIConverter.createOutputStream(outPath);
      final WritableByteChannel outChannel = Channels.newChannel(_createOutputStream);
      while ((new Function0<Integer>() {
        public Integer apply() {
          try {
            int _read = inChannel.read(buffer);
View Full Code Here

  protected org.eclipse.emf.common.util.URI createURI(EObject o) {
    IEObjectDescription target = documentationProvider.xref(o);
    if(target == null)
      return null; // should disable the link as well

    final URIConverter uriConverter = o.eResource().getResourceSet().getURIConverter();
    final URI uri = target.getEObjectURI();
    final URI normalized = uriConverter.normalize(uri);
    return normalized;
  }
View Full Code Here

  public void createHyperlinksTo(XtextResource from, Region region, IEObjectDescription to,
      IHyperlinkAcceptor acceptor) {
    if(!isAcceptableTarget(to))
      return;
    final URIConverter uriConverter = from.getResourceSet().getURIConverter();
    final String hyperlinkText = labelProvider.getText(to);
    final URI uri = to.getEObjectURI();
    final URI normalized = uriConverter.normalize(uri);

    XtextHyperlink result = getHyperlinkProvider().get();
    result.setHyperlinkRegion(region);
    result.setURI(normalized);
    result.setHyperlinkText(hyperlinkText);
View Full Code Here

      // use an URI Converter to allow possible model extender to rewrite
      // URI
      // TODO replace with ExtensibleURIConverterImpl once EMF dep moves
      // up to 2.4
      URIConverter uriConverter = new URIConverterImpl();
      URI uri = uriConverter.normalize(URI.createURI(name));

      // set Authority to host and port of the service
      final java.net.URI location = anIServiceInfo.getLocation();
      final String authority = location.getAuthority();
      uri = URI.createHierarchicalURI(uri.scheme(), authority,
View Full Code Here

TOP

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

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.