Package org.eclipse.emf.ecore.resource

Examples of org.eclipse.emf.ecore.resource.URIConverter$WriteableOutputStream$Buffer


    }
  }

  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

   * except as arguments to the q option.
   */
  static Varargs format( Varargs args ) {
    LuaString fmt = args.checkstring( 1 );
    final int n = fmt.length();
    Buffer result = new Buffer(n);
    int arg = 1;
    int c;
   
    for ( int i = 0; i < n; ) {
      switch ( c = fmt.luaByte( i++ ) ) {
      case '\n':
        result.append( "\n" );
        break;
      default:
        result.append( (byte) c );
        break;
      case L_ESC:
        if ( i < n ) {
          if ( ( c = fmt.luaByte( i ) ) == L_ESC ) {
            ++i;
            result.append( (byte)L_ESC );
          } else {
            arg++;
            FormatDesc fdsc = new FormatDesc(args, fmt, i );
            i += fdsc.length;
            switch ( fdsc.conversion ) {
            case 'c':
              fdsc.format( result, (byte)args.checkint( arg ) );
              break;
            case 'i':
            case 'd':
              fdsc.format( result, args.checkint( arg ) );
              break;
            case 'o':
            case 'u':
            case 'x':
            case 'X':
              fdsc.format( result, args.checklong( arg ) );
              break;
            case 'e':
            case 'E':
            case 'f':
            case 'g':
            case 'G':
              fdsc.format( result, args.checkdouble( arg ) );
              break;
            case 'q':
              addquoted( result, args.checkstring( arg ) );
              break;
            case 's': {
              LuaString s = args.checkstring( arg );
              if ( fdsc.precision == -1 && s.length() >= 100 ) {
                result.append( s );
              } else {
                fdsc.format( result, s );
              }
            }  break;
            default:
              error("invalid option '%"+(char)fdsc.conversion+"' to 'format'");
              break;
            }
          }
        }
      }
    }
   
    return result.tostring();
  }
View Full Code Here

    LuaString p = args.checkstring( 2 );
    LuaValue repl = args.arg( 3 );
    int max_s = args.optint( 4, srclen + 1 );
    final boolean anchor = p.length() > 0 && p.charAt( 0 ) == '^';
   
    Buffer lbuf = new Buffer( srclen );
    MatchState ms = new MatchState( args, src, p );
   
    int soffset = 0;
    int n = 0;
    while ( n < max_s ) {
      ms.reset();
      int res = ms.match( soffset, anchor ? 1 : 0 );
      if ( res != -1 ) {
        n++;
        ms.add_value( lbuf, soffset, res, repl );
      }
      if ( res != -1 && res > soffset )
        soffset = res;
      else if ( soffset < srclen )
        lbuf.append( (byte) src.luaByte( soffset++ ) );
      else
        break;
      if ( anchor )
        break;
    }
    lbuf.append( src.substring( soffset, srclen ) );
    return varargsOf(lbuf.tostring(), valueOf(n));
  }
View Full Code Here

TOP

Related Classes of org.eclipse.emf.ecore.resource.URIConverter$WriteableOutputStream$Buffer

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.