use of java.util.Vector in project ansj_seg by NLPchina.
the class File2Stream method multiple.
private InputStream multiple(String path) throws FileNotFoundException {
File[] libs = new File[0];
File file = new File(path);
if (file.exists() && file.canRead()) {
if (file.isFile()) {
libs = new File[1];
libs[0] = file;
} else if (file.isDirectory()) {
File[] files = file.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.canRead() && !file.isHidden() && !file.isDirectory();
}
});
if (files != null && files.length > 0) {
libs = files;
}
}
}
if (libs.length == 0) {
throw new LibraryException("not find any file in path : " + path);
}
if (libs.length == 1) {
return new FileInputStream(libs[0]);
}
Vector<InputStream> vector = new Vector<>(libs.length);
for (int i = 0; i < libs.length; i++) {
vector.add(new FileInputStream(libs[i]));
}
return new SequenceInputStream(vector.elements());
}
use of java.util.Vector in project Hystrix by Netflix.
the class HystrixPluginsTest method setupMockServiceLoader.
private HystrixPlugins setupMockServiceLoader() throws Exception {
final ClassLoader realLoader = HystrixPlugins.class.getClassLoader();
ClassLoader loader = new WrappedClassLoader(realLoader) {
@Override
public Enumeration<URL> getResources(String name) throws IOException {
dynamicPropertyEvents.add("serviceloader: " + name);
final Enumeration<URL> r;
if (name.endsWith("META-INF/services/com.netflix.hystrix.strategy.properties.HystrixDynamicProperties")) {
Vector<URL> vs = new Vector<URL>();
URL u = super.getResource(fakeServiceLoaderResource);
vs.add(u);
return vs.elements();
} else {
r = super.getResources(name);
}
return r;
}
};
final Logger mockLogger = (Logger) Proxy.newProxyInstance(realLoader, new Class<?>[] { Logger.class }, new MockLoggerInvocationHandler());
return HystrixPlugins.create(loader, new LoggerSupplier() {
@Override
public Logger getLogger() {
return mockLogger;
}
});
}
use of java.util.Vector in project screenbird by adamhub.
the class AudioRecorder method addEmptySound.
/**
* Adds a silent audio to the recorded audio as padding to fix the difference
* between the actual and targeted start times.
* @param startTimestamp
* @param correctStartTimestamp
* @return
* @throws UnsupportedAudioFileException
*/
public static AudioInputStream addEmptySound(long startTimestamp, long correctStartTimestamp) throws UnsupportedAudioFileException {
AudioInputStream emptyAudioStream = null;
AudioFormat format = null;
long prevLength = 0;
long secondsRounded = (long) Math.ceil((((double) (startTimestamp - correctStartTimestamp)) / 1000.0));
long realMillis = startTimestamp - correctStartTimestamp;
log("silent duration rounded: " + secondsRounded);
log("silent duration millis: " + realMillis);
log("current file start:" + startTimestamp);
log("current file correct start :" + correctStartTimestamp);
try {
Vector<AudioInputStream> emptyStreams = new Vector<AudioInputStream>();
for (int i = 0; i < secondsRounded; i++) {
InputStream emptyAudioFileWav = getSilentWav();
if (emptyAudioFileWav != null) {
emptyAudioStream = AudioSystem.getAudioInputStream(emptyAudioFileWav);
prevLength += emptyAudioStream.getFrameLength();
format = emptyAudioStream.getFormat();
emptyStreams.add(emptyAudioStream);
}
}
if (emptyStreams.size() > 0) {
String empty = recordingDir + FileUtil.addExtension(String.valueOf(System.currentTimeMillis()), "empty");
File file = new File(empty);
AudioRecorder.compileAudioStreams(emptyStreams, file, format, prevLength);
AudioRecorder.cutAudioFile(file, realMillis);
emptyAudioStream = AudioSystem.getAudioInputStream(file);
}
} catch (IOException ex) {
}
log("silent length in millis after cut: " + String.valueOf(emptyAudioStream.getFrameLength() / emptyAudioStream.getFormat().getFrameRate()));
log("===================");
return emptyAudioStream;
}
use of java.util.Vector in project screenbird by adamhub.
the class Atom method getFieldName.
protected static String getFieldName(Class c, int i) {
Vector answers = new Vector();
Field[] f = c.getFields();
for (int a = 0; a < f.length; a++) {
if (((f[a].getModifiers() & Modifier.STATIC) > 0) && (f[a].getType() == Integer.TYPE || f[a].getType() == Integer.class)) {
try {
int k = ((Number) f[a].get(null)).intValue();
if (k == i)
answers.add(f[a].getName());
} catch (Exception e) {
}
}
}
if (answers.size() == 0)
return "unknown";
if (answers.size() == 1)
return (String) answers.get(0);
StringBuffer sb = new StringBuffer();
sb.append("[");
for (int a = 0; a < answers.size(); a++) {
if (a != 0) {
sb.append(", ");
}
sb.append("\"" + answers.get(a) + "\"");
}
sb.append("]");
return sb.toString();
}
use of java.util.Vector in project screenbird by adamhub.
the class AtomFactory method readAll.
public static synchronized Atom[] readAll(File file) throws IOException {
InputStream in = null;
try {
in = new FileInputStream(file);
MeasuredInputStream in2 = new MeasuredInputStream(in);
Vector v = new Vector();
while (in2.getReadBytes() < file.length()) {
Atom atom = read(null, in2);
v.add(atom);
}
return (Atom[]) v.toArray(new Atom[v.size()]);
} finally {
try {
in.close();
} catch (Exception e) {
}
}
}
Aggregations