1 package fi.vtt.simantics.procore.internal;
3 import org.simantics.db.AsyncReadGraph;
4 import org.simantics.db.DirectStatements;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.RelationInfo;
7 import org.simantics.db.Resource;
8 import org.simantics.db.common.procedure.wrapper.NoneToAsyncProcedure;
9 import org.simantics.db.common.procedure.wrapper.SyncToAsyncProcedure;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.impl.ClusterI;
12 import org.simantics.db.impl.ClusterI.ClusterTypeEnum;
13 import org.simantics.db.impl.ForEachObjectContextProcedure;
14 import org.simantics.db.impl.ForEachObjectProcedure;
15 import org.simantics.db.impl.ForPossibleRelatedValueContextProcedure;
16 import org.simantics.db.impl.ForPossibleRelatedValueProcedure;
17 import org.simantics.db.impl.ResourceImpl;
18 import org.simantics.db.impl.TransientGraph;
19 import org.simantics.db.impl.graph.ReadGraphImpl;
20 import org.simantics.db.procedure.AsyncContextMultiProcedure;
21 import org.simantics.db.procedure.AsyncContextProcedure;
22 import org.simantics.db.procedure.AsyncMultiProcedure;
23 import org.simantics.db.procedure.AsyncProcedure;
24 import org.simantics.db.procedure.Procedure;
25 import org.simantics.db.procedure.SyncProcedure;
26 import org.simantics.db.procore.cluster.ClusterBig;
27 import org.simantics.db.procore.cluster.ClusterImpl;
28 import org.simantics.db.procore.cluster.ClusterSmall;
29 import org.simantics.db.procore.cluster.ResourceTableSmall;
30 import org.simantics.db.procore.cluster.ValueTableSmall;
31 import org.simantics.db.request.AsyncRead;
32 import org.simantics.db.service.DirectQuerySupport;
34 public class DirectQuerySupportImpl implements DirectQuerySupport {
36 final private SessionImplSocket session;
38 DirectQuerySupportImpl(SessionImplSocket session) {
39 this.session = session;
43 final public void forEachDirectPersistentStatement(AsyncReadGraph graph, final Resource subject, final AsyncProcedure<DirectStatements> procedure) {
44 ReadGraphImpl impl = (ReadGraphImpl)graph;
45 impl.processor.forEachDirectStatement(impl, subject, procedure, true);
49 final public void forEachDirectStatement(AsyncReadGraph graph, final Resource subject, final AsyncProcedure<DirectStatements> procedure) {
50 ReadGraphImpl impl = (ReadGraphImpl)graph;
51 impl.processor.forEachDirectStatement(impl, subject, procedure, false);
55 public void forEachDirectStatement(AsyncReadGraph graph, Resource subject, SyncProcedure<DirectStatements> procedure) {
56 forEachDirectStatement(graph, subject, new SyncToAsyncProcedure<DirectStatements>(procedure));
60 public void forEachDirectStatement(AsyncReadGraph graph, Resource subject, Procedure<DirectStatements> procedure) {
61 ReadGraphImpl impl = (ReadGraphImpl)graph;
62 impl.processor.forEachDirectStatement(impl, subject, procedure);
66 public void forRelationInfo(AsyncReadGraph graph, Resource subject, AsyncProcedure<RelationInfo> procedure) {
67 ReadGraphImpl impl = (ReadGraphImpl)graph;
68 impl.processor.forRelationInfo(impl, subject, procedure);
72 public void forRelationInfo(AsyncReadGraph graph, Resource subject, SyncProcedure<RelationInfo> procedure) {
73 forRelationInfo(graph, subject, new SyncToAsyncProcedure<RelationInfo>(procedure));
77 public void forRelationInfo(AsyncReadGraph graph, Resource subject, Procedure<RelationInfo> procedure) {
78 forRelationInfo(graph, subject, new NoneToAsyncProcedure<RelationInfo>(procedure));
82 public AsyncMultiProcedure<Resource> compileForEachObject(ReadGraph graph, final Resource relation, AsyncMultiProcedure<Resource> user) {
85 RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
88 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
89 forRelationInfo(graph, relation, procedure);
93 public int threadHash() {
98 public int getFlags() {
103 final int predicateKey = ((ResourceImpl)relation).id;
104 return new ForEachObjectProcedure(predicateKey, info, session.queryProvider2, user);
105 } catch (DatabaseException e) {
112 public <C> AsyncContextMultiProcedure<C, Resource> compileForEachObject(ReadGraph graph, final Resource relation, AsyncContextMultiProcedure<C, Resource> user) {
115 RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
118 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
119 forRelationInfo(graph, relation, procedure);
123 public int threadHash() {
128 public int getFlags() {
133 final int predicateKey = ((ResourceImpl)relation).id;
134 return new ForEachObjectContextProcedure<C>(predicateKey, info, session.queryProvider2, user);
135 } catch (DatabaseException e) {
142 public <T> AsyncProcedure<T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, AsyncProcedure<T> user) {
145 RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
148 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
149 forRelationInfo(graph, relation, procedure);
153 public int threadHash() {
158 public int getFlags() {
163 final int predicateKey = ((ResourceImpl)relation).id;
164 return new ForPossibleRelatedValueProcedure<T>(predicateKey, info, user);
165 } catch (DatabaseException e) {
172 public <C, T> AsyncContextProcedure<C, T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, AsyncContextProcedure<C, T> user) {
175 RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
178 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
179 forRelationInfo(graph, relation, procedure);
183 public int threadHash() {
188 public int getFlags() {
193 final int predicateKey = ((ResourceImpl)relation).id;
194 return new ForPossibleRelatedValueContextProcedure<C, T>(predicateKey, info, user);
195 } catch (DatabaseException e) {
202 public void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, final AsyncMultiProcedure<Resource> procedure) {
204 assert(subject != null);
206 final ForEachObjectProcedure proc = (ForEachObjectProcedure)procedure;
207 // final RelationInfo info = proc.info;
209 final ReadGraphImpl impl = (ReadGraphImpl)graph;
210 final int subjectId = ((ResourceImpl)subject).id;
212 // int callerThread = impl.callerThread;
213 // int suggestSchedule = (subjectId>>16) & queryProvider2.THREAD_MASK;
217 // if(callerThread == suggestSchedule) {
219 // if(info.isFunctional) {
220 // querySupport.getObjects4(impl, subjectId, proc);
222 session.querySupport.getObjects4(impl, subjectId, proc);
227 // impl.state.barrier.inc();
228 // impl.state.barrier.dec(callerThread);
230 // queryProvider2.schedule(callerThread, new SessionTask(suggestSchedule) {
233 // public void run(int thread) {
235 // impl.state.barrier.inc(thread);
236 // impl.state.barrier.dec();
238 // if(info.isFunctional) {
239 // querySupport.getObjects4(impl.newAsync(thread), subjectId, proc);
241 // querySupport.getObjects4(impl.newAsync(thread), subjectId, proc);
247 // public String toString() {
258 public <C> void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, C context, final AsyncContextMultiProcedure<C, Resource> procedure) {
260 assert(subject != null);
262 final ForEachObjectContextProcedure<C> proc = (ForEachObjectContextProcedure<C>)procedure;
263 final RelationInfo info = proc.info;
265 final ReadGraphImpl impl = (ReadGraphImpl)graph;
266 final int subjectId = ((ResourceImpl)subject).id;
268 // int callerThread = impl.callerThread;
269 // int suggestSchedule = (subjectId>>16) & queryProvider2.THREAD_MASK;
273 if(info.isFunctional) {
274 session.querySupport.getObjects4(impl, subjectId, context, proc);
276 session.querySupport.getObjects4(impl, subjectId, context, proc);
282 public <T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, final AsyncProcedure<T> procedure) {
284 assert(subject != null);
286 final ForPossibleRelatedValueProcedure<T> proc = (ForPossibleRelatedValueProcedure<T>)procedure;
287 final RelationInfo info = proc.info;
289 final ReadGraphImpl impl = (ReadGraphImpl)graph;
290 final int subjectId = ((ResourceImpl)subject).id;
292 // int callerThread = impl.callerThread;
293 // int suggestSchedule = (subjectId>>16) & session.queryProvider2.THREAD_MASK;
297 // if(callerThread == suggestSchedule) {
299 if(info.isFunctional) {
300 getRelatedValue4(impl, subjectId, proc);
302 getRelatedValue4(impl, subjectId, proc);
307 // impl.state.barrier.inc();
308 // impl.state.barrier.dec(callerThread);
310 // queryProvider2.schedule(callerThread, new SessionTask(suggestSchedule) {
313 // public void run(int thread) {
315 // impl.state.barrier.inc(thread);
316 // impl.state.barrier.dec();
318 // if(info.isFunctional) {
319 // getRelatedValue4(impl.newAsync(thread), subjectId, proc);
321 // getRelatedValue4(impl.newAsync(thread), subjectId, proc);
327 // public String toString() {
338 public <C, T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, C context, final AsyncContextProcedure<C, T> procedure) {
340 assert(subject != null);
342 final ForPossibleRelatedValueContextProcedure<C, T> proc = (ForPossibleRelatedValueContextProcedure<C, T>)procedure;
343 final RelationInfo info = proc.info;
345 final ReadGraphImpl impl = (ReadGraphImpl)graph;
346 final int subjectId = ((ResourceImpl)subject).id;
348 // int callerThread = impl.callerThread;
349 // int suggestSchedule = (subjectId>>16) & session.queryProvider2.THREAD_MASK;
353 if(info.isFunctional) {
354 getRelatedValue4(impl, subjectId, context, proc);
356 getRelatedValue4(impl, subjectId, context, proc);
362 public <T> void forPossibleType(final AsyncReadGraph graph, Resource subject, final AsyncProcedure<Resource> procedure) {
364 assert(subject != null);
366 final ReadGraphImpl impl = (ReadGraphImpl)graph;
367 final int subjectId = ((ResourceImpl)subject).id;
371 final ClusterI cluster = session.clusterTable.getClusterByResourceKey(subjectId);
372 if(!cluster.isLoaded()) {
374 // impl.state.inc(0);
376 session.queryProvider2.requestCluster(impl, cluster.getClusterId(), new Runnable() {
383 int result = cluster.getCompleteObjectKey(subjectId, session.clusterTranslator);
384 procedure.execute(graph, new ResourceImpl(session.resourceSupport, result));
386 // impl.state.dec(0);
388 } catch (DatabaseException e) {
398 int result = cluster.getCompleteObjectKey(subjectId, session.clusterTranslator);
399 procedure.execute(graph, new ResourceImpl(session.resourceSupport, result));
403 } catch (DatabaseException e) {
412 public <C> void forPossibleDirectType(final AsyncReadGraph graph, Resource subject, final C context, final AsyncContextProcedure<C, Resource> procedure) {
414 assert(subject != null);
416 final ReadGraphImpl impl = (ReadGraphImpl)graph;
417 final int subjectId = ((ResourceImpl)subject).id;
421 final ClusterI cluster = session.clusterTable.getClusterByResourceKey(subjectId);
422 if(!cluster.isLoaded()) {
424 // impl.state.inc(0);
426 session.queryProvider2.requestCluster(impl, cluster.getClusterId(), new Runnable() {
433 ClusterI.CompleteTypeEnum type = cluster.getCompleteType(subjectId, session.clusterTranslator);
434 if(ClusterI.CompleteTypeEnum.InstanceOf == type) {
435 int result = cluster.getCompleteObjectKey(subjectId, session.clusterTranslator);
436 procedure.execute(graph, context, new ResourceImpl(session.resourceSupport, result));
438 procedure.execute(graph, context, null);
441 // impl.state.dec(0);
443 } catch (DatabaseException e) {
453 ClusterI.CompleteTypeEnum type = cluster.getCompleteType(subjectId, session.clusterTranslator);
454 if(ClusterI.CompleteTypeEnum.InstanceOf == type) {
455 int result = cluster.getCompleteObjectKey(subjectId, session.clusterTranslator);
456 procedure.execute(graph, context, new ResourceImpl(session.resourceSupport, result));
458 procedure.execute(graph, context, null);
463 } catch (DatabaseException e) {
465 procedure.execute(graph, context, null);
467 } catch (Throwable t) {
470 procedure.execute(graph, context, null);
477 private <C, T> void getRelatedValue4(final ReadGraphImpl graph, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
481 final int predicate = procedure.predicateKey;
485 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
486 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
487 g -> getRelatedValue4(g, subject, context, procedure)
492 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
493 for (int id : g.getObjects(subject, predicate)) {
495 procedure.exception(graph, new DatabaseException("Multiple objects"));
506 procedure.exception(graph, new DatabaseException("No objects for " + subject ));
512 getValue4(graph, null, result, context, procedure);
519 final org.simantics.db.procore.cluster.ClusterImpl cluster = session.clusterTable.getClusterByResourceKey(subject);
520 if(!cluster.isLoaded()) {
521 cluster.load(session.clusterTranslator, () -> getRelatedValue4(graph, subject, context, procedure));
525 if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
527 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
528 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
529 g -> getRelatedValue4(g, subject, context, procedure)
534 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
535 for (int id : g.getObjects(subject, predicate)) {
537 procedure.exception(graph, new DatabaseException("Multiple objects"));
546 getRelatedDirectValue4(graph, cluster, subject, result, context, procedure);
550 getRelatedDirectValue4(graph, cluster, subject, 0, context, procedure);
556 private <T> void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
558 Object result = null;
562 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
563 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
564 g -> getValue4(g, containerCluster, subject, procedure)
569 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
570 Object value = g.getValue(subject);
573 procedure.exception(graph, new DatabaseException("Multiple values"));
582 procedure.execute(graph, (T)"name");
588 ClusterImpl cluster = containerCluster;
589 if(!containerCluster.contains(subject)) {
590 cluster = session.clusterTable.getClusterByResourceKey(subject);
591 if(!cluster.isLoaded()) {
592 cluster.load(session.clusterTranslator, new Runnable() {
596 getValue4(graph, containerCluster, subject, procedure);
604 if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
606 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
607 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
608 g -> getValue4(g, containerCluster, subject, procedure)
613 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
614 Object value = g.getValue(subject);
617 procedure.exception(graph, new DatabaseException("Multiple values"));
628 procedure.execute(graph, (T)result);
629 // graph.state.barrier.dec();
633 if(ClusterTypeEnum.SMALL == cluster.getType())
634 getDirectValue4(graph, (ClusterSmall)cluster, subject, procedure);
636 getDirectValue4(graph, (ClusterBig)cluster, subject, procedure);
641 if(ClusterTypeEnum.SMALL == cluster.getType())
642 getDirectValue4(graph, (ClusterSmall)cluster, subject, procedure);
644 getDirectValue4(graph, (ClusterBig)cluster, subject, procedure);
650 private <C, T> void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
652 Object result = null;
656 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
657 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
658 g -> getValue4(g, containerCluster, subject, context, procedure)
663 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
664 Object value = g.getValue(subject);
667 procedure.exception(graph, new DatabaseException("Multiple values"));
676 procedure.execute(graph, context, (T)"name");
682 ClusterImpl cluster = containerCluster;
683 if(!containerCluster.contains(subject)) {
684 cluster = session.clusterTable.getClusterByResourceKey(subject);
685 if(!cluster.isLoaded()) {
686 cluster.load(session.clusterTranslator, new Runnable() {
690 getValue4(graph, containerCluster, subject, context, procedure);
698 if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
700 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
701 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
702 g -> getValue4(g, containerCluster, subject, context, procedure)
707 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
708 Object value = g.getValue(subject);
711 procedure.exception(graph, new DatabaseException("Multiple values"));
722 procedure.execute(graph, context, (T)result);
723 // graph.state.barrier.dec();
727 if(ClusterTypeEnum.SMALL == cluster.getType())
728 getDirectValue4(graph, (ClusterSmall)cluster, subject, context, procedure);
730 getDirectValue4(graph, (ClusterBig)cluster, subject, context, procedure);
735 if(ClusterTypeEnum.SMALL == cluster.getType())
736 getDirectValue4(graph, (ClusterSmall)cluster, subject, context, procedure);
738 getDirectValue4(graph, (ClusterBig)cluster, subject, context, procedure);
744 private <T> void getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final ForPossibleRelatedValueProcedure<T> procedure) {
748 int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
751 procedure.exception(graph, new DatabaseException("No objects " + subject + " " + procedure.predicateKey));
754 getValue4(graph, cluster, result, procedure);
758 getValue4(graph, cluster, so, procedure);
760 procedure.exception(graph, new DatabaseException("Multiple objects"));
765 } catch (DatabaseException e) {
771 private <C, T> void getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
775 int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
778 procedure.exception(graph, new DatabaseException("No objects " + subject + " " + procedure.predicateKey));
781 getValue4(graph, cluster, result, context, procedure);
785 getValue4(graph, cluster, so, context, procedure);
787 procedure.exception(graph, new DatabaseException("Multiple objects"));
792 } catch (DatabaseException e) {
798 public <T> void getRelatedValue4(final ReadGraphImpl graph, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
802 final int predicate = procedure.predicateKey;
806 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
807 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
808 g -> getRelatedValue4(g, subject, procedure)
813 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
814 for (int id : g.getObjects(subject, predicate)) {
816 procedure.exception(graph, new DatabaseException("Multiple objects"));
827 procedure.exception(graph, new DatabaseException("No objects for " + subject ));
833 getValue4(graph, null, result, procedure);
840 final org.simantics.db.procore.cluster.ClusterImpl cluster = session.clusterTable.getClusterByResourceKey(subject);
841 if(!cluster.isLoaded()) {
842 cluster.load(session.clusterTranslator, new Runnable() {
846 getRelatedValue4(graph, subject, procedure);
853 if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
855 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
856 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
857 g -> getRelatedValue4(graph, subject, procedure)
862 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
863 for (int id : g.getObjects(subject, predicate)) {
865 procedure.exception(graph, new DatabaseException("Multiple objects"));
874 getRelatedDirectValue4(graph, cluster, subject, result, procedure);
878 getRelatedDirectValue4(graph, cluster, subject, 0, procedure);
884 private <C, T> void getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
887 byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
888 T value = (T)utf(bytes);
889 procedure.execute(graph, context, value);
890 } catch (DatabaseException e) {
891 procedure.execute(graph, context, null);
898 private <T> void getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
901 byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
902 T value = (T)utf(bytes);
903 procedure.execute(graph, value);
904 } catch (DatabaseException e) {
905 procedure.execute(graph, null);
912 private <C, T> void getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
915 byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
917 procedure.execute(graph, context, null);
919 T value = (T)utf(bytes);
920 procedure.execute(graph, context, value);
922 } catch (DatabaseException e) {
923 procedure.execute(graph, context, null);
930 private final char[] chars = new char[1024];
932 private <T> void getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
934 ResourceTableSmall rt = cluster.resourceTable;
935 ValueTableSmall vt = cluster.valueTable;
937 byte[] bs = vt.table;
938 long[] ls = rt.table;
940 int index = ((subject&0xFFFF) << 1) - 1 + rt.offset;
942 int valueIndex = (int)(ls[index] >>> 24) & 0x3FFFFF + vt.offset;
944 int size = (int)bs[valueIndex++]-1;
946 for(int i=0;i<size;i++) {
947 chars[i] = (char)bs[valueIndex++];
950 T value = (T)new String(chars, 0, size);
952 procedure.execute(graph, value);
957 final private String utf(byte[] bytes) {
959 if(bytes == null) return null;
962 int length = bytes[index++]&0xff;
968 length += ((bytes[index++]&0xff)<<3);
969 length += ((bytes[index++]&0xff)<<11);
970 length += ((bytes[index++]&0xff)<<19);
971 length += 0x10204080;
975 length += ((bytes[index++]&0xff)<<4);
976 length += ((bytes[index++]&0xff)<<12);
977 length += ((bytes[index++]&0xff)<<20);
983 length += ((bytes[index++]&0xff)<<5);
984 length += ((bytes[index++]&0xff)<<13);
990 length += ((bytes[index++]&0xff)<<6);
996 int target = length+index;
997 while(index < target) {
998 int c = bytes[index++]&0xff;
1000 chars[i++] = (char)(c&0x7F);
1001 } else if (c > 0x07FF) {
1002 int c2 = bytes[index++]&0xff;
1003 int c3 = bytes[index++]&0xff;
1004 chars[i++] = (char)(((c&0xf)<<12) + ((c2&0x3f)<<6) + (c3&0x3f));
1006 int c2 = bytes[index++]&0xff;
1007 chars[i++] = (char)(((c&0x1f)<<6) + (c2&0x3f));
1011 // if (!((c >= 0x0001) && (c <= 0x007F))) {
1015 // if ((c >= 0x0001) && (c <= 0x007F)) {
1016 // bytearr[byteIndex++] = (byte)( c );
1017 // } else if (c > 0x07FF) {
1018 // bytearr[byteIndex++] = (byte)(0xE0 | ((c >> 12) & 0x0F));
1019 // bytearr[byteIndex++] = (byte)(0x80 | ((c >> 6) & 0x3F));
1020 // bytearr[byteIndex++] = (byte)(0x80 | ((c >> 0) & 0x3F));
1022 // bytearr[byteIndex++] = (byte)(0xC0 | ((c >> 6) & 0x1F));
1023 // bytearr[byteIndex++] = (byte)(0x80 | ((c >> 0) & 0x3F));
1029 return new String(chars, 0, i);