Initial import into git.
[galago.git] / java / pig-galago / src / com / yahoo / pig / data / BagFactory.java
blob7017d00d5eba14f7c8ac0af4ec69a8ff90d041e1
1 /*
2 * Copyright (c) 2007 Yahoo! Inc. All rights reserved.
3 * See accompanying LICENSE file.
4 */
5 package com.yahoo.pig.data;
7 import java.io.File;
8 import java.io.IOException;
10 public class BagFactory {
12 private File tmpdir = null;
13 private static BagFactory instance = new BagFactory();
15 public static BagFactory getInstance() {
16 return instance;
19 private BagFactory() {
22 public static void init(File tmpdir) {
23 instance.setTmpDir(tmpdir);
26 private void setTmpDir(File tmpdir) {
27 this.tmpdir = tmpdir;
28 this.tmpdir.mkdirs();
31 // Get BigBag or Bag, depending on whether the temp directory has been set up
32 public DataBag getNewBag() throws IOException {
33 if (tmpdir == null) return new DataBag();
34 else return getNewBigBag();
37 // Need a Big Bag, dammit!
38 public BigDataBag getNewBigBag() throws IOException {
39 if (tmpdir == null) throw new IOException("No temp directory given for BigDataBag.");
40 else return new BigDataBag(tmpdir);