X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Flocal%2FAbsData.java;h=cdc0e486c407d5023217c463d8fff20cd4324785;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=17edae42e6669f2509c514378b018de9331465e0;hpb=b126c6c5f625432722405538692184f5c74edaad;p=aaf%2Fauthz.git diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/local/AbsData.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/local/AbsData.java index 17edae42..cdc0e486 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/local/AbsData.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/local/AbsData.java @@ -7,9 +7,9 @@ * Licensed 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. @@ -35,172 +35,172 @@ import org.onap.aaf.misc.env.Env; import org.onap.aaf.misc.env.TimeTaken; public abstract class AbsData implements Iterable { - protected DataFile data; - protected TextIndex ti; - private File dataf,idxf,lockf; - private String name; - private char delim; - private int maxLineSize; - private int fieldOffset; - private int skipLines; - - public AbsData(File dataf,char sepChar, int maxLineSize, int fieldOffset) { - File dir = dataf.getParentFile(); - int dot = dataf.getName().lastIndexOf('.'); - name = dataf.getName().substring(0,dot); - - this.dataf=dataf; - this.delim = sepChar; - this.maxLineSize = maxLineSize; - this.fieldOffset = fieldOffset; - idxf = new File(dir,name.concat(".idx")); - lockf = new File(dir,name.concat(".lock")); - - - data = new DataFile(dataf,"r"); - ti = new TextIndex(idxf); - skipLines=0; - } - - public void skipLines(int lines) { - skipLines=lines; - } - - public String name() { - return name; - } - - public void open(AuthzTrans trans, long timeout) throws IOException { - TimeTaken tt = trans.start("Open Data File", Env.SUB); - boolean first = true; - try { - if(!dataf.exists()) { - throw new FileNotFoundException("Data File Missing:" + dataf.getCanonicalPath()); - } - long begin = System.currentTimeMillis(); - long end = begin+timeout; - boolean exists; - while((exists=lockf.exists()) && beginidxf.lastModified()) { - trans.warn().log(idxf.getAbsolutePath(),"is missing, empty or out of date, creating"); - RandomAccessFile raf = new RandomAccessFile(lockf, "rw"); - try { - ti.create(trans, data, maxLineSize, delim, fieldOffset, skipLines); - if(!idxf.exists() || (idxf.length()==0 && dataf.length()!=0)) { - throw new IOException("Data Index File did not create correctly"); - } - } finally { - raf.close(); - lockf.delete(); - } - } - } - - public void close(AuthzTrans trans) throws IOException { - ti.close(); - data.close(); - } - - public class Reuse { - public Token tokenData; - private Field fieldData; - - private Reuse(int size,char delim) { - tokenData = data.new Token(size); - fieldData = tokenData.new Field(delim); - } - - public void reset() { - getFieldData().reset(); - } - - public void pos(int rec) { - getFieldData().reset(); - tokenData.pos(rec); - } - - public String next() { - return getFieldData().next(); - } - - public String at(int field) { - return getFieldData().at(field); - } - - public String atToEnd(int field) { - return getFieldData().atToEnd(field); - } - - public Field getFieldData() { - return fieldData; - } - } - - public Reuse reuse() { - return new Reuse(maxLineSize,delim); - } - - public Iter iterator() { - return new Iter(); - } - - public class Iter implements Iterator { - private Reuse reuse; - private org.onap.aaf.auth.local.TextIndex.Iter tii; - - public Iter() { - reuse = reuse(); - tii = ti.new Iter(); - } - - @Override - public boolean hasNext() { - return tii.hasNext(); - } - - @Override - public String next() { - if(!hasNext()) { - throw new NoSuchElementException(); - } - reuse.reset(); - int rec = tii.next(); - reuse.pos(rec); - return reuse.at(0); - } - - @Override - public void remove() { - // read only - } - } + protected DataFile data; + protected TextIndex ti; + private File dataf,idxf,lockf; + private String name; + private char delim; + private int maxLineSize; + private int fieldOffset; + private int skipLines; + + public AbsData(File dataf,char sepChar, int maxLineSize, int fieldOffset) { + File dir = dataf.getParentFile(); + int dot = dataf.getName().lastIndexOf('.'); + name = dataf.getName().substring(0,dot); + + this.dataf=dataf; + this.delim = sepChar; + this.maxLineSize = maxLineSize; + this.fieldOffset = fieldOffset; + idxf = new File(dir,name.concat(".idx")); + lockf = new File(dir,name.concat(".lock")); + + + data = new DataFile(dataf,"r"); + ti = new TextIndex(idxf); + skipLines=0; + } + + public void skipLines(int lines) { + skipLines=lines; + } + + public String name() { + return name; + } + + public void open(AuthzTrans trans, long timeout) throws IOException { + TimeTaken tt = trans.start("Open Data File", Env.SUB); + boolean first = true; + try { + if (!dataf.exists()) { + throw new FileNotFoundException("Data File Missing:" + dataf.getCanonicalPath()); + } + long begin = System.currentTimeMillis(); + long end = begin+timeout; + boolean exists; + while ((exists=lockf.exists()) && beginidxf.lastModified()) { + trans.warn().log(idxf.getAbsolutePath(),"is missing, empty or out of date, creating"); + RandomAccessFile raf = new RandomAccessFile(lockf, "rw"); + try { + ti.create(trans, data, maxLineSize, delim, fieldOffset, skipLines); + if (!idxf.exists() || (idxf.length()==0 && dataf.length()!=0)) { + throw new IOException("Data Index File did not create correctly"); + } + } finally { + raf.close(); + lockf.delete(); + } + } + } + + public void close(AuthzTrans trans) throws IOException { + ti.close(); + data.close(); + } + + public class Reuse { + public Token tokenData; + private Field fieldData; + + private Reuse(int size,char delim) { + tokenData = data.new Token(size); + fieldData = tokenData.new Field(delim); + } + + public void reset() { + getFieldData().reset(); + } + + public void pos(int rec) { + getFieldData().reset(); + tokenData.pos(rec); + } + + public String next() { + return getFieldData().next(); + } + + public String at(int field) { + return getFieldData().at(field); + } + + public String atToEnd(int field) { + return getFieldData().atToEnd(field); + } + + public Field getFieldData() { + return fieldData; + } + } + + public Reuse reuse() { + return new Reuse(maxLineSize,delim); + } + + public Iter iterator() { + return new Iter(); + } + + public class Iter implements Iterator { + private Reuse reuse; + private org.onap.aaf.auth.local.TextIndex.Iter tii; + + public Iter() { + reuse = reuse(); + tii = ti.new Iter(); + } + + @Override + public boolean hasNext() { + return tii.hasNext(); + } + + @Override + public String next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + reuse.reset(); + int rec = tii.next(); + reuse.pos(rec); + return reuse.at(0); + } + + @Override + public void remove() { + // read only + } + } }