You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2013/12/05 13:31:03 UTC

[10/52] git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2 into PocEdmAnnotationsExtension

Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2 into PocEdmAnnotationsExtension


Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/4e6734d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/4e6734d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/4e6734d4

Branch: refs/heads/master
Commit: 4e6734d4b223289a2dd960578cd39399e977fc4a
Parents: 5af5559 5c3319b
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Oct 15 22:02:07 2013 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Oct 15 22:32:56 2013 +0200

----------------------------------------------------------------------
 .../ref/annotation/model/ResourceHelper.java    | 57 +++++++-------------
 1 file changed, 18 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4e6734d4/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --cc odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
index 07ee5b4,0000000..bba1c6b
mode 100644,000000..100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
@@@ -1,107 -1,0 +1,86 @@@
 +/*******************************************************************************
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements. See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership. The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License. You may obtain a copy of the License at
 + * 
 + * http://www.apache.org/licenses/LICENSE-2.0
 + * 
 + * Unless required by applicable law or agreed to in writing,
 + * software distributed under the License is distributed on an
 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 + * KIND, either express or implied. See the License for the
 + * specific language governing permissions and limitations
 + * under the License.
 + ******************************************************************************/
 +package org.apache.olingo.odata2.ref.annotation.model;
 +
 +import java.awt.image.BufferedImage;
 +import java.awt.image.WritableRaster;
 +import java.io.ByteArrayOutputStream;
 +import java.io.IOException;
 +import java.io.InputStream;
- import java.nio.ByteBuffer;
- import java.util.logging.Level;
- import java.util.logging.Logger;
 +import javax.imageio.ImageIO;
- import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
 +
 +/**
 + *
 + */
 +class ResourceHelper {
 +
 +  public static byte[] loadAsByte(String resource) {
 +    return load(resource, new byte[0]);
 +  }
 +
 +  public static byte[] load(String resource, byte[] defaultResult) {
 +    InputStream instream = null;
 +    try {
 +      instream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
 +      if (instream == null) {
 +        return defaultResult;
 +      }
 +      ByteArrayOutputStream stream = new ByteArrayOutputStream();
 +      int b = 0;
 +      while ((b = instream.read()) != -1) {
 +        stream.write(b);
 +      }
 +
 +      return stream.toByteArray();
 +    } catch (IOException e) {
 +      throw new RuntimeException(e);
 +    } finally {
 +      if(instream != null) {
 +        try {
 +          instream.close();
 +        } catch (IOException ex) { }
 +      }
 +    }
 +  }
 +
-   static byte[] generateImage() {
++  public static byte[] generateImage() {
 +    try {
-       //    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- //    String format = "PNG";
- //    int width = 200;
- //    int height = 200;
- //    int imageType = BufferedImage.TYPE_BYTE_BINARY;
- //    BufferedImage image = new BufferedImage(width, height, imageType);
- //    ImageIO.write(image, format, outStream);
- //    return null;
++      int width = 320;
++      int height = 320;
++      BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
++      WritableRaster raster = image.getRaster();
 +      
-       return test();
-     } catch (IOException ex) {
-       return new byte[0];
-     }
-   }
-   
-   private static byte[] test() throws IOException {
-     int width = 400; // Dimensions of the image
-     int height = 400;
-     // Let's create a BufferedImage for a binary image.
-     BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
-     // We need its raster to set the pixels' values.
-     WritableRaster raster = im.getRaster();
-        // Put the pixels on the raster. Note that only values 0 and 1 are used for the pixels.
-     // You could even use other values: in this type of image, even values are black and odd
-     // values are white.
-     for (int h = 0; h < height; h++) {
-       for (int w = 0; w < width; w++) {
-         if (((h / 50) + (w / 50)) % 2 == 0) {
-           raster.setSample(w, h, 0, 0); // checkerboard pattern.
-         } else {
-           raster.setSample(w, h, 0, 1);
++      for (int h = 0; h < height; h++) {
++        for (int w = 0; w < width; w++) {
++          if (((h / 32) + (w / 32)) % 2 == 0) {
++            raster.setSample(w, h, 0, 0);
++          } else {
++            raster.setSample(w, h, 0, 1);
++          }
 +        }
 +      }
++      
++      ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
++      ImageIO.write(image, "PNG", out);
++      return out.toByteArray();
++    } catch (IOException ex) {
++      return new byte[0];
 +    }
-     // Store the image using the PNG format.
-     ByteArrayOutputStream out = new ByteArrayOutputStream(1024*10);
-     ImageIO.write(im, "PNG", out);
-     return out.toByteArray();
 +  }
 +}