All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jcp.xml.dsig.internal.dom.Utils Maven / Gradle / Ivy

The newest version!
/*    */ package org.jcp.xml.dsig.internal.dom;
/*    */ 
/*    */ import java.io.ByteArrayOutputStream;
/*    */ import java.io.IOException;
/*    */ import java.io.InputStream;
/*    */ import java.util.HashSet;
/*    */ import java.util.Iterator;
/*    */ import java.util.Set;
/*    */ import org.w3c.dom.NamedNodeMap;
/*    */ import org.w3c.dom.Node;
/*    */ 
/*    */ public final class Utils
/*    */ {
/*    */   public static byte[] readBytesFromStream(InputStream is)
/*    */     throws IOException
/*    */   {
/* 27 */     ByteArrayOutputStream baos = new ByteArrayOutputStream();
/* 28 */     byte[] buf = new byte[1024];
/*    */     while (true) {
/* 30 */       int read = is.read(buf);
/* 31 */       if (read == -1) {
/*    */         break;
/*    */       }
/* 34 */       baos.write(buf, 0, read);
/* 35 */       if (read < 1024) {
/*    */         break;
/*    */       }
/*    */     }
/* 39 */     return baos.toByteArray();
/*    */   }
/*    */ 
/*    */   static Set toNodeSet(Iterator i)
/*    */   {
/* 50 */     Set nodeSet = new HashSet();
/* 51 */     while (i.hasNext()) {
/* 52 */       Node n = (Node)i.next();
/* 53 */       nodeSet.add(n);
/*    */ 
/* 55 */       if (n.getNodeType() == 1) {
/* 56 */         NamedNodeMap nnm = n.getAttributes();
/* 57 */         int j = 0; for (int length = nnm.getLength(); j < length; j++) {
/* 58 */           nodeSet.add(nnm.item(j));
/*    */         }
/*    */       }
/*    */     }
/* 62 */     return nodeSet;
/*    */   }
/*    */ 
/*    */   public static String parseIdFromSameDocumentURI(String uri)
/*    */   {
/* 69 */     if (uri.length() == 0) {
/* 70 */       return null;
/*    */     }
/* 72 */     String id = uri.substring(1);
/* 73 */     if ((id != null) && (id.startsWith("xpointer(id("))) {
/* 74 */       int i1 = id.indexOf('\'');
/* 75 */       int i2 = id.indexOf('\'', i1 + 1);
/* 76 */       id = id.substring(i1 + 1, i2);
/*    */     }
/* 78 */     return id;
/*    */   }
/*    */ 
/*    */   public static boolean sameDocumentURI(String uri)
/*    */   {
/* 85 */     return (uri != null) && ((uri.length() == 0) || (uri.charAt(0) == '#'));
/*    */   }
/*    */ }

/* Location:           E:\HYN\Java\trunk\ref\lib-dep\xmldsig\xmldsig.jar
 * Qualified Name:     org.jcp.xml.dsig.internal.dom.Utils
 * JD-Core Version:    0.6.2
 */




© 2015 - 2024 Weber Informatics LLC | Privacy Policy