Search in sources :

Example 6 with Vector

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());
}
Also used : SequenceInputStream(java.io.SequenceInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) LibraryException(org.ansj.exception.LibraryException) FileFilter(java.io.FileFilter) File(java.io.File) Vector(java.util.Vector) FileInputStream(java.io.FileInputStream)

Example 7 with Vector

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;
        }
    });
}
Also used : LoggerSupplier(com.netflix.hystrix.strategy.HystrixPlugins.LoggerSupplier) Logger(org.slf4j.Logger) Vector(java.util.Vector) URL(java.net.URL)

Example 8 with Vector

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;
}
Also used : AudioInputStream(javax.sound.sampled.AudioInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) AudioInputStream(javax.sound.sampled.AudioInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) AudioFormat(javax.sound.sampled.AudioFormat) Vector(java.util.Vector) File(java.io.File)

Example 9 with Vector

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();
}
Also used : Field(java.lang.reflect.Field) Vector(java.util.Vector) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 10 with Vector

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) {
        }
    }
}
Also used : MeasuredInputStream(com.bric.io.MeasuredInputStream) FileInputStream(java.io.FileInputStream) GuardedInputStream(com.bric.io.GuardedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MeasuredInputStream(com.bric.io.MeasuredInputStream) Vector(java.util.Vector) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Aggregations

Vector (java.util.Vector)3045 IOException (java.io.IOException)239 ArrayList (java.util.ArrayList)224 Test (org.junit.Test)182 Enumeration (java.util.Enumeration)174 Iterator (java.util.Iterator)173 Hashtable (java.util.Hashtable)170 File (java.io.File)159 List (java.util.List)143 HashMap (java.util.HashMap)128 ResultSet (java.sql.ResultSet)122 SQLException (java.sql.SQLException)95 Collection (java.util.Collection)87 PreparedStatement (java.sql.PreparedStatement)79 StringTokenizer (java.util.StringTokenizer)79 Statement (java.sql.Statement)60 Fault (com.sun.ts.lib.harness.EETest.Fault)54 HashSet (java.util.HashSet)54 Expression (cbit.vcell.parser.Expression)52 Map (java.util.Map)50